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

查看:46
本文介绍了如何检测 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 anyway on the SDK to know when a uitableview loading has finished? I see nothing neither on delegate nor on data source protocols.

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

I can't use the count of the data sources because of 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天全站免登陆