How to get a UITableView's visible sections?

前端 未结 12 1811
轻奢々
轻奢々 2020-12-14 19:24

UITableView provides the methods indexPathsForVisibleRows and visibleCells, but how can I get the visible sections?

12条回答
  •  渐次进展
    2020-12-14 20:25

    Or the really easy way would be to take advantage of valueForKeyPath and the NSSet class:

    NSSet *visibleSections = [NSSet setWithArray:[[self.tableView indexPathsForVisibleRows] valueForKey:@"section"]];
    

    Basically you get an array of the section values in the visible rows and then populate a set with this to remove duplicates.

提交回复
热议问题