Getting visible cell from UITableView pagingEnabled

前端 未结 5 1900
孤城傲影
孤城傲影 2020-12-13 15:35

I have a UITableView with pagingEnabled. Each cell takes up the viewing area of the table. Meaning, each cell is the same height and width as the table. I\'m using custom

5条回答
  •  生来不讨喜
    2020-12-13 16:14

    Well, on the off chance that you never figured out a solution, or for whoever comes to this question next, I'll provide you with the answer you were looking for. UITableView will provide you with the indexPaths you are looking for, and then UITableView will happily provide you with the cells that match those index paths:

    UITableView *tableView = self.tableView; // Or however you get your table view
    NSArray *paths = [tableView indexPathsForVisibleRows];
    
    //  For getting the cells themselves
    NSMutableSet *visibleCells = [[NSMutableSet alloc] init];
    
    for (NSIndexPath *path in paths) {
        [visibleCells addObject:[tableView cellForRowAtIndexPath:path]];
    }
    
    // Now visibleCells contains all of the cells you care about.
    

提交回复
热议问题