![](/img/trans.png)
[英]How do I pass indexPath (not indexPath.row) into my IBAction for my UITableViewCell
[英]How can I get a uitableViewCell by indexPath.row or only row number instead of indexpath?
我们可以像这样轻松地从 indexPath 获取 UITableViewCell:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
但是我只有行号而不是索引路径,我正在使用此代码来获取单元格。
NSArray *visible = [self.tableView indexPathsForVisibleRows];
NSIndexPath *indexpath = (NSIndexPath*)[visible objectAtIndex:MyRowNumber];
UITableViewCell *tablecell = [self.tableView cellForRowAtIndexPath:indexpath];
告诉我这是否是一个好的方法,如果不是,哪个是。
您可以使用行号创建一个新的NSIndexPath
(假设您的表只有一个部分)。
NSIndexPath *indexPath= [NSIndexPath indexPathForRow:yourRowNumber inSection:0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.