UITableView
provides the methods indexPathsForVisibleRows
and visibleCells
, but how can I get the visible sections?
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.
Swift version
if let visibleRows = tableView.indexPathsForVisibleRows {
let visibleSections = visibleRows.map({$0.section})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With