簡體   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