如何检测UITableView的加载结束 [英] How to detect the end of loading of UITableView

查看:118
本文介绍了如何检测UITableView的加载结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在加载完成时更改表的偏移量,并且该偏移量取决于表上加载的单元格数。

I want to change the offset of the table when the load is finished and that offset depends on the number of cells loaded on the table.

SDK是否可以知道uitableview加载何时完成?我在委托和数据源协议上都没有看到任何内容。

Is it any way on the SDK to know when a uitableview loading has finished? I don't see nothing neither on delegate nor on data source protocols.

我无法使用数据源的计数,因为只加载了可见单元格。

I can't use the count of the data sources because the loading of the visible cells only.

推荐答案

改善@RichX答案:
lastRow 可以是 [tableView numberOfRowsInSection:0] - 1 ((NSIndexPath *)[[tableView indexPathsForVisibleRows] lastObject])。row
因此代码将是:

Improve to @RichX answer: lastRow can be both [tableView numberOfRowsInSection: 0] - 1 or ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row. So the code will be:

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
        //end of loading
        //for example [activityIndicator stopAnimating];
    }
}

更新:
好吧,@ htafoya的评论是对的。如果您希望此代码检测从源加载所有数据的结束,则不会,但这不是原始问题。此代码用于检测何时显示所有可见的单元格。 willDisplayCell:此处用于更流畅的UI(单个单元格通常在 willDisplay:调用后快速显示)。您也可以尝试使用 tableView:didEndDisplayingCell:

UPDATE: Well, @htafoya's comment is right. If you want this code to detect end of loading all data from source, it wouldn't, but that's not the original question. This code is for detecting when all cells that are meant to be visible are displayed. willDisplayCell: used here for smoother UI (single cell usually displays fast after willDisplay: call). You could also try it with tableView:didEndDisplayingCell:.

这篇关于如何检测UITableView的加载结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆