複数の行を持つUITableViewがあるとしましょう。特定の時点ですべてのUITableViewCellを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;
}
しかし、このアプローチでは、画面に表示されていないセルを取得できないようです。誰かがこれについて私を助けることができますか?