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

如何在ios Swift中禁用一个特定的tableView单元格,ios,swift,uitableview,didselectrowatindexpath,Ios,Swift,Uitableview,Didselectrowatindexpath,我已创建自定义UITableViewCell。我的tableView中只有两行。现在我想禁用第二个单元格,当第1个单元格被点击时,禁用第1个单元格,当第2个单元格被点击时。 我该怎么做?请帮助并指导执行UITableViewDelegate方法将选择Rowatindexpath 在该方法中,如果希望用户能够选择,则返回传递给您的indepath值;如果不希望用户能够选择,则返回nil override func tableView(tableView: UITableView, didSelec

我已创建自定义UITableViewCell。我的tableView中只有两行。现在我想禁用第二个单元格,当第1个单元格被点击时,禁用第1个单元格,当第2个单元格被点击时。
我该怎么做?请帮助并指导执行
UITableViewDelegate
方法
将选择Rowatindexpath

在该方法中,如果希望用户能够选择,则返回传递给您的
indepath
值;如果不希望用户能够选择,则返回nil

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

我将把它留给您去弄清楚决定不同单元格何时应该/不应该被选择的逻辑。

实现
UITableViewDelegate
方法
willselectrowatinexpath

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
  tableView.cellForRowAtIndexPath(NSIndexPath(forRow: (indexPath.row + 1) % 2, inSection: 0))?.userInteractionEnabled = false
}
在该方法中,如果希望用户能够选择,则返回传递给您的
indepath
值;如果不希望用户能够选择,则返回nil

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

我将留给您去弄清楚决定何时应该/不应该选择不同单元格的逻辑。

您是否检查了
UITableViewCell
选择
?您可以在需要启用和禁用邮件id时维护bool数组并更新值。我将向您发送演示。我也有同样的问题。我可以用我的代码更新这个问题吗?@VishalSonawaneumairafzal10@yahoo.comDid您可以检查
UITableViewCell
选项
?您可以在需要启用和禁用邮件id时维护布尔数组并更新值。我将向您发送演示。我也有同样的问题。我可以用我的代码更新这个问题吗?@VishalSonawaneumairafzal10@yahoo.comNo,这是一个UITableViewDelegate方法,它不允许您控制哪些项可选择或不可选择。不,这是一个UITableViewDelegate方法,它不允许您控制哪些项可选择或不可选择。为什么不使用“shouldHighlight”方法检查它?从逻辑上讲,我认为这比返回一个nil indexath要好,请给出建议。提前谢谢。为什么不用“shoulldhighlight”方法检查呢?从逻辑上讲,我认为这比返回一个nil indexath要好,请给出建议。先谢谢你。
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
  tableView.cellForRowAtIndexPath(NSIndexPath(forRow: (indexPath.row + 1) % 2, inSection: 0))?.userInteractionEnabled = false
}