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(@"加載數據");
}
}