2010-11-30 46 views
13

我在我的应用程序中有多个UITableViews,有没有一种方法来检测用户在该列中选择了哪个单元格/行?UITableView检测选定的细胞?

也有可能以编程方式取消选择一个单元格/行?

谢谢。

回答

30

获取当前选择的索引路径表:

NSIndexPath *path = [tableView indexPathForSelectedRow]; 

取消当前所选行:

[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES]; 
2
NSIndexPath *path = [tableView indexPathForSelectedRow]; 

上面一行将抛出EXC错误访问如果没有卖的是选择,以便跟踪与NSIndexPath实例变量在所选单元格中,只有取消当实际上是选用isSelected属性的单元格。

UITableViewCell *cell = [tableView cellForRowAtIndexPath:someIndexPath]; 
if(cell.isSelected) { 
    [tableView deselectRowAtIndexPath:someIndexPath animated:YES]; 
}