【问题标题】:How can I unselect my row selected in objective c?如何取消选择在目标 c 中选择的行?
【发布时间】:2016-12-30 15:16:10
【问题描述】:

我想取消选择之前选择的行,再次选择此行。我只能在其他行中单击取消选择该行,但我想再次单击该行取消选择。我该怎么做?

这是我的代码:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
[self updateTableView];
 }

 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
 {
[self updateTableView];
}


 - (void)updateTableView
{
[self.tableView beginUpdates];
[self.tableView endUpdates];
}

谢谢!!

【问题讨论】:

标签: objective-c uitableview cell


【解决方案1】:

使用属性跟踪选定的索引路径。在tableView:didSelectRowAtIndexPath: 中,将您存储的索引路径与委托方法中提供的索引路径进行比较。如果它们相同,则表示该行已被选中。调用deselectRowAtIndexPath:animated: 取消选择它并将存储的索引路径设置为nil。否则,将存储的索引路径更新为委托方法中提供的索引路径。

【讨论】:

    【解决方案2】:

    tableviews 中有一个 deselectRowAtIndexPath 方法。使用该方法传递您的索引路径。

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      • 2019-08-08
      • 2018-05-06
      • 2017-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多