繁体   English   中英

点击另一行时如何取消选择一行?

[英]How to deselect a row when another row tapped?

这是我要存档的内容:点击第二个中文行时取消选择“英语”行,或者相反。

图片

我只希望显示一个复选标记,而不是全部显示。 这是我的代码:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if tableView.cellForRow(at: indexPath)!.accessoryType == .checkmark  {
        tableView.cellForRow(at: indexPath)!.accessoryType = .none
        navigationItem.rightBarButtonItem!.isEnabled = false
    } else if tableView.cellForRow(at: indexPath)!.accessoryType == .none   {
        tableView.cellForRow(at: indexPath)!.accessoryType = .checkmark
        navigationItem.rightBarButtonItem!.isEnabled = true
    }
}

最后,我得到了答案。 干得好:

   func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.cellForRow(at: indexPath)!.accessoryType = .checkmark
        navigationItem.rightBarButtonItem?.isEnabled = true
    }

    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        tableView.cellForRow(at: indexPath)!.accessoryType = .none
        navigationItem.rightBarButtonItem?.isEnabled = false
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM