How to get a UITableView's visible sections?

前端 未结 12 1797
轻奢々
轻奢々 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:09

    UITableViews store their cells using an NSIndexPath. As a result there is no object for sections. Using the following code we can traverse the table and perform operations using the indexes of visible sections (I'm not sure why you want visible sections since visible only means they are currently on the screen, but whatever).

    for (NSIndexPath* i in [yourTableViewName indexPathsForVisibleRows])
    {
      NSUInteger sectionPath = [i indexAtPosition:0];
      //custom code here, will run multiple times per section for each visible row in the group
    }
    

提交回复
热议问题