how to retrieve all visible table section header views

后端 未结 10 578
渐次进展
渐次进展 2020-12-31 04:44

is there a way to get all the section header views that are visible?

something similar to UITableView\'s visibleCells instance method..

10条回答
  •  旧巷少年郎
    2020-12-31 05:25

    For a plain style table, you can get the visible rows. From those, get the set of visible sections. And from that, get the section header views from the table.

    NSArray *visibleRows = [self.tableView indexPathsForVisibleRows];
    NSMutableIndexSet *sections = [[NSMutableIndexSet alloc] init];
    for (NSIndexPath *indexPath in visibleRows) {
        [sections addIndex:indexPath.section];
    }
    
    NSMutableArray *headerViews = [NSMutableArray array];
    [sections enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
        UIView *view = [self.tableView headerViewForSection:idx];
        [headerViews addObject:view];
    }];
    

    Note: code not tested - may contain typos. This won't work 100% for a grouped style table.

提交回复
热议问题