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

标签 ios swift uitableview

这是我要归档的内容:当点击第二个中文行时取消选择“英文”行,反之亦然。

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
    }
}

最佳答案

我终于得到了答案。给你:

   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
    }

关于ios - 如何在点击另一行时取消选择一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47533152/

相关文章:

ios - 尝试仅允许在单个特定行上进行滑动行为

ios - 检查用户 ID(Firebase 和 Swift)

ios - PDF 第一页在 iOS 中不显示

objective-c - UINavigationController 在 TableView 上使用分组?

objective-c - objective-c : UITableView Scrolling becomes Laggy

objective-c - 在 UIImageView 的图像上方绘制贝塞尔曲线

iphone - 如何根据 tableviewcell 选择将 subview 的 nsdictionary 保存到主视图

ios - 不显示加速度计/陀螺仪 View

swift - 排序 Int 的排序数组

swift - 空合并运算符的简写和可重新生成属性的赋值?