Tej*_*tel 2 objective-c uitableview ios
我想找到完整的可见细胞索引UITableView.在这里,我有附加图像.
在此图像中,数字1和数字12不完全可见,因此它不应返回该单元格的索引.我只想要完全可见的细胞索引,只有2,3,4,5,6,7,8,9,10,11.
您可以使用indexPathsForVisibleRows获取所有可见,然后使用cellRect rectForRowAtIndexPath并检查单元格是否包含在tableview的绑定中.
NSMutableArray *arr = [[NSMutableArray alloc]init];
for (NSIndexPath *indexVisible in tableView.indexPathsForVisibleRows) {
CGRect cellRect = [tableView rectForRowAtIndexPath:indexVisible];
BOOL isVisible = CGRectContainsRect(tableView.bounds, cellRect);
if (isVisible) {
//you can also add rows if you dont want full indexPath.
//[arr addObject:[NSString stringWithFormat:@"%ld",(long)indexVisible.row]];
[arr addObject:indexVisible];
}
}
NSLog(@"%@",arr);
Run Code Online (Sandbox Code Playgroud)
希望这会帮助你.
| 归档时间: |
|
| 查看次数: |
1834 次 |
| 最近记录: |