【问题标题】:how to store tableview cell checkmark state in popover?如何在popover中存储tableview单元格复选标记状态?
【发布时间】:2017-08-08 11:34:40
【问题描述】:

我在初始视图控制器中有几个按钮。单击任何按钮时将出现一个带有可扩展表格视图的弹出窗口。我正在对所有具有不同数据的按钮使用单个弹出框来显示在 tableview 上。当我单击第一个按钮时,弹出窗口中的选定项目正在被删除,当我单击其他按钮时,所有这些都将被删除。所选项目将保存到基于 indexpath.row 的数组中。当我尝试从基于相同 indexpath.row 的同一数组中删除所选项目时,出现异常错误。

如何为所有弹出框存储每个单元格选择的复选标记?

这是我的一段代码

func expandableTableView(_ expandableTableView: LUExpandableTableView, didSelectRowAt indexPath: IndexPath)
{
    let selectedService = arrData[indexPath.section].Children?[indexPath.row].EnglishName ?? ""
    let inPrice = arrData[indexPath.section].Children?[indexPath.row].InPrice ?? 0
    print("service and price : \(selectedService) \(inPrice)")
    let selectedItem = (" \(selectedService) \(inPrice)")
    let cell: UITableViewCell? = expandableTableView.cellForRow(at: indexPath)
    if cell?.accessoryType == UITableViewCellAccessoryType.none
    {
        cell?.accessoryType = UITableViewCellAccessoryType.checkmark
        selectionArr.append(selectedItem)
        inPriceCount =  inPrice
    }
    else
    {
        cell?.accessoryType = UITableViewCellAccessoryType.none
            selectionArr.remove(at: indexPath.row)
            inPriceCount =  -inPrice
    }
    self.delegate?.messageData(data: selectionArr as AnyObject)
    self.delegate?.inPrice(data: inPriceCount as AnyObject)
    let rowToSelect = [expandableTableView .indexPathForSelectedRow]
    print(rowToSelect)

}

【问题讨论】:

    标签: ios uitableview swift3 nsuserdefaults


    【解决方案1】:

    你不应该从数组中删除任何东西。只需在每个索引上添加一个键

    dict["ischeckMarked"]=false
    

    当你改变点击复选标记改变它真实

    dict["ischeckMarked"]=true
    

    如果已经选中,现在您想取消标记,请将其更改为 false

    dict["ischeckMarked"]=false
    

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-03-22
      • 1970-01-01
      • 2018-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多