Swift : 在静态表视图中保存并显示选定的 indexPath



我的静态桌面有一个小问题。我有一个弹出窗口,作为我的网格的选项。我想保存我的静态tableview的状态(indexpath(,但似乎不起作用,以下是我的摘要代码:

 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    var currSelected: IndexPath?
    let section = indexPath.section
    let numberOfRows = tableView.numberOfRows(inSection: section)
    for row in 0..<numberOfRows {
        if let cell = tableView.cellForRow(at: NSIndexPath(row: row, section: section) as IndexPath) {
            cell.accessoryType = row == indexPath.row ? .checkmark : .none
            tableView.deselectRow(at: indexPath, animated: false)
            currSelected = indexPath
            if section == 2 {
                tableView.deselectRow(at: indexPath, animated: false)
                cell.accessoryType = .none
            }
            else {
                delegate?.option(lastSelected: currSelected!)
                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reload"), object: nil)
            }
        }
    }
}

我正在尝试使用delegatelastSelected(最后一个IndexPath(扔到上一个控制器上,然后通过控制器将其发送回POP,我得到了它。但是我不知道使用该检查标记使用最后选择。并且prepare for cell at功能需要重复使用的单元格的标识符,但我不使用它。

我已经阅读了以显示检查标记,但并不能保存状态。我也读过,但也一样。任何建议/答案都会对我有所帮助。预先感谢

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    if indexPath == lastSelected {
        cell.accessoryType = .Checkmark
    }
}

最新更新