繁体   English   中英

UITableView检测选定的单元格?

[英]UITableView Detect Selected Cell?

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

还有可能以编程方式取消选择单元/行吗?

谢谢。

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

NSIndexPath *path = [tableView indexPathForSelectedRow];

取消选择当前选中的行:

[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];

这些都可以在UITableView的文档中轻松找到。 也许您下次应该第一次去那里。

甚至还有一个链接: http : //developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html

NSIndexPath *path = [tableView indexPathForSelectedRow];

如果未选择任何卖出,则上面的行将引发EXC BAD ACCESS ,因此使用NSIndexPath实例变量跟踪所选单元格,并且仅在使用cell的isSelected属性实际选择时才取消选择。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM