Скажем, у меня есть 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;
}
но кажется, что этот подход все еще не может получить те ячейки, которые не отображаются на экране. Может ли кто-нибудь помочь мне в этом?