【问题标题】:How can I get a uitableViewCell by indexPath.row or only row number instead of indexpath?如何通过 indexPath.row 或仅行号而不是 indexpath 获取 uitableViewCell?
【发布时间】:2015-09-15 06:20:18
【问题描述】:

我们可以像这样轻松地从 indexPath 获取 UITableViewCell:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

但我只有行号而不是索引路径,我正在使用此代码获取单元格。

NSArray *visible       = [self.tableView indexPathsForVisibleRows];
NSIndexPath *indexpath = (NSIndexPath*)[visible objectAtIndex:MyRowNumber];
UITableViewCell *tablecell = [self.tableView cellForRowAtIndexPath:indexpath];

告诉我这是否是一个好的方法,如果不是,那是哪一个。

【问题讨论】:

标签: ios objective-c xcode


【解决方案1】:

您可以使用行号创建一个新的NSIndexPath(假设您的表格只有一个部分)。

NSIndexPath *indexPath= [NSIndexPath indexPathForRow:yourRowNumber inSection:0];

【讨论】:

    猜你喜欢
    • 2011-01-23
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多