开发者

UITableView - get list of UITableViewCells in an indexPath.section

开发者 https://www.devze.com 2022-12-21 02:15 出处:网络
Is there a way I can iterate over a list of UITableViewCells contained in开发者_如何学Go an indexPath.section?

Is there a way I can iterate over a list of UITableViewCells contained in开发者_如何学Go an indexPath.section?

Thanks


You can use UITableView's cellForRowAtIndexPath: to get a cell at a specific index. But this will only return a cell if it is currently visible in the table.

What are you really trying to do? Why do you need all cells in a section?


It's long ago that this question was asked but this might help other people searching for a solution.

NSInteger mySectionIdentifier = 0;
NSArray *visibleCells = self.tableView.visibleCells;
NSMutableArray *sectionCells = [NSMutableArray arrayWithCapacity:visibleCells.count];

for (UITableViewCell *cell in visibleCells) {
    NSIndexPath *cellIndexPath = [self.tableView indexPathForCell:cell];
    if (cellIndexPath.section == mySectionIdentifier) {
        [sectionCells addObject:cell];
    }
}

As you see this only works for visible cells but it would be easy to change the code to retrieve all cells instead of the visible ones.

0

精彩评论

暂无评论...
验证码 换一张
取 消