简体   繁体   English

如何在iOS Swift中禁用一个特定的tableView单元格

[英]How to disable one specific tableView cell in ios Swift

I have created a custom UITableViewCell.I have only two rows in my tableView. 我创建了一个自定义的UITableViewCell.tableView中只有两行。 Now I want to disable 2nd cell when 1st is tapped and disable 1st cell when 2nd is tapped. 现在,我想在点击第一个时禁用第二个单元格,并在点击第二个时禁用第一个单元格。 How can I do that ? 我怎样才能做到这一点 ? please Help and guide 请帮助和指导

Implement the UITableViewDelegate method willSelectRowAtIndexPath . 实现UITableViewDelegate方法willSelectRowAtIndexPath

In that method, return the indexPath value that's passed to you if you want the user to be able to select it, or return nil if you don't want it to be selectable. 在该方法中,如果希望用户能够选择它,则返回传递给您的indexPath值;如果不希望它是可选择的,则返回nil。

I'll leave it to you to figure out the logic that decides when different cells should/should not be selectable. 我将留给您找出决定何时应该/不应该选择不同单元格的逻辑。

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
  tableView.cellForRowAtIndexPath(NSIndexPath(forRow: (indexPath.row + 1) % 2, inSection: 0))?.userInteractionEnabled = false
}

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

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