【发布时间】:2011-09-22 20:01:26
【问题描述】:
UITableViewDelegate 有一种方法可以识别我在tableView 中选择了哪一行。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
但是我怎么知道我选择了哪一行呢?
【问题讨论】:
标签: iphone row selection uitableview
UITableViewDelegate 有一种方法可以识别我在tableView 中选择了哪一行。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
但是我怎么知道我选择了哪一行呢?
【问题讨论】:
标签: iphone row selection uitableview
在您的datamodel 中,您可以有一个 int 变量来了解数据被选择了多少次。在您在问题中提到的方法中增加它。我希望你现在明白了。您不能使用单元格来维持计数,因为它们会被重复使用。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
获取数据和 indexpath.row 并增加计数。
【讨论】:
只需在didSelectRowAtIndexPath: 中创建一个整数int count,然后在选择行时将count 加一。简单的逻辑。
【讨论】: