代码之家  ›  专栏  ›  技术社区  ›  Vincent

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

  •  0
  • Vincent  · 技术社区  · 8 年前

    以下是我想要归档的内容:当第二个中文行点击时取消选择“English”行,或者相反。

    Picture

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

    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
        }
    }
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Vincent    8 年前

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

       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
        }