假设我有一个包含多行的 UITableView。我想在某个时间点将所有 UITableViewCells 作为 NSArray 获取。我努力了
[tableView visibleCells]
但这种方法有一个问题:我无法拥有当前不在当前屏幕中的所有单元格。所以我转向另一种方法:
-(NSArray *)cellsForTableView:(UITableView *)tableView
{
NSInteger sections = tableView.numberOfSections;
NSMutableArray *cells = [[NSMutableArray alloc] init];
for (int section = 0; section < sections; section++) {
NSInteger rows = [tableView numberOfRowsInSection:section];
for (int row = 0; row < rows; row++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; // **here, for those cells not in current screen, cell is nil**
[cells addObject:cell];
}
}
return cells;
}
但似乎这种方法仍然无法获取那些未显示在屏幕上的单元格。谁可以帮我这个事?
我认为这是不可能的,因为 tableView 不存储所有单元格。它使用缓存机制,仅存储一些不可见的单元以供重用。
为什么需要所有细胞?也许你可以实现你想要做的事情,否则。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)