如何获取UITable视图可见路径和更多行

时间:2013-03-12 14:06:35

标签: iphone ios uitableview

现在我正在获取可见tableview单元格的索引路径。但是我想从可见行中再获取3个索引路径,我该怎么做?

NSArray *visiblePaths = [tblView indexPathsForVisibleRows];

1 个答案:

答案 0 :(得分:1)

假设只有一个部分,您可以创建它们,注意该部分的最大行数:

NSMutableArray *visiblePaths = [tblView indexPathsForVisibleRows] mutableCopy];
NSInteger lastIndexPath = [visiblePaths lastObject];
NSInteger lastRow = lastIndexPath.row;
NSInteger extraRows = 3;
NSInteger maxRow = MIN(lastRow+extraRows, [self tableView:tblView numberOfRowsInSection:0] - 1);

for (int i = lastRow+1; i < maxRow; i++) {
    NSIndexPath *newPath = [NSIndexPath indexPathForRow:i inSection:0];
    [visiblePaths addObject:newPath];
}

对于更多部分(和/或第一个可见之前的行)也是可行的。希望很清楚如何扩展它以满足这些要求。