判断tableViewCell是否在可视区

1、- (NSArray *)visibleCells;

UITableview 的方法,这个最直接,返回一个UITableviewcell的数组。

对于自定义的cell,之后的处理可能会稍微复杂。

2、-(NSArray*)indexPathsForVisibleRows;

UITableview的又一个方法,这个比较好用,返回一个indexPath的数组,可以直接indexpath.row去调用你的table_related_array里的数据了。比较方便用于自定制的cell.

3、-(CGRect)rectForRowAtIndexPath:(NSIndexPath*)indexPath;

//找出indexPath为index对应的cell在myTV这个tableView里的rect

CGRect cellR = [myTV rectForRowAtIndexPath:index];

如果myTV.contentOffset - cellR.origin.y < myCll.frame.size.height;

或者cellR.origin.y - myTV.contentOffset.y > myTV.size.height;

这个时候myCell应该不在myTV的可视区域了

这个方法可以用在代理回调较多的设计中。

、、

1、2在自动根据数据伸长的cell中好像不太准确、

删除UITableviewCell时,如何知道最后一个cell显示在了屏幕上面。如果一个屏幕10个cell,删除了两个。最后一个cell出现在了屏幕上,需要

自动加载更多数据。

如果cell大小固定。数据源数量 小于 屏幕高度除以cell高。这时可以继续加载。

如果cell大小根据内容自动变化。(cell高度动态变化)

//数据源数组

NSArray *dataArray = nil;

//获取最后一个cell对象

UITableViewCell *cell = self.tableView.visibleCells.lastObject;

//获取最后一个cell的indexPath

NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

//获取指定(最后)一个cell的rect

CGRect rect = [self.tableView rectForRowAtIndexPath:indexPath];

CGFloat lastCellBottom = rect.origin.y = rect.size.height;

id lastModel = dataArray.lastObject;

id model = dataArray[indexPath.row];

//保证是最后一个cell

if(model == lastModel){

  if(lastCellBottom < self.tableView.frame.size.height){

    NSLog(@"加载数据");

  }

}

原文地址:https://www.cnblogs.com/wjw-blog/p/7810078.html