如何取消选择在目标c中选择的行?

时间:2016-08-23 17:14:28

标签: objective-c uitableview cell

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

这是我的代码:

 - (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];
}

谢谢!

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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