iOS UITableview获取可视范围内的Cell和indexpath

56 阅读1分钟

1、获取可视范围内的Cell

NSArray *array = [self.tableView visibleCells];
for (UITableViewCell *cell in array) {
    if ([cell isKindOfClass:[VPPhoneTableViewCell class]]) {
        VPPhoneTableViewCell *phoneCell = (VPPhoneTableViewCell *)cell;
        phoneCell.callbackButton.hidden = !phoneCell.callbackButton.hidden;
    }
}

2、获取可视范围内的indexpath/获取可视范围内的section

NSArray<NSIndexPath *> *indexPaths = [self.tableView indexPathsForVisibleRows];
int section = indexPaths.firstObject.section;