how to retrieve all visible table section header views

后端 未结 10 632
渐次进展
渐次进展 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:14

    to get the current visible sections, u could get it by checking the current visible cells indexpath section, so this function could return to u the visible sections

    - (NSArray *)indexesOfVisibleSections {
    
        NSMutableArray *visibleSections = [NSMutableArray array];
    
        for (UITableViewCell * cell in [self.tableView visibleCells]) {
            if (![visibleSections containsObject:[NSNumber numberWithInteger:[self.tableView indexPathForCell:cell].section]]) {
                [visibleSections addObject:[NSNumber numberWithInteger:[self.tableView indexPathForCell:cell].section]];
            }
        }
    
        return visibleSections;
    }
    

    And to access section view , u can use

    - (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section;
    

提交回复
热议问题