2016-08-23 108 views
-3

我想取消选择先前选择的行再次选择。我只能取消选中该行点击其他行,但我想再次取消选择此点击。我怎样才能做到这一点?如何取消选择在目标c中选择的行?

这是我的代码:

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

谢谢!

+0

请在发布问题之前检查是否存在相关的问题。 http://stackoverflow.com/questions/3968037/how-to-deselect-a-selected-uitableview-cell –

回答

0

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

0

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

相关问题