且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当 UITableView 完成请求数据时得到通知?

更新时间:2023-11-20 23:06:04

此答案似乎不再有效,因为自编写答案以来对 UITableView 实现进行了一些更改.请参阅此评论:UITableView 完成时收到通知要求提供数据?

我已经解决这个问题几天了,我认为子类化 UITableViewreloadData 是***的方法:

I've been playing with this problem for a couple of days and think that subclassing UITableView's reloadData is the best approach :

- (void)reloadData {

    NSLog(@"BEGIN reloadData");

    [super reloadData];

    NSLog(@"END reloadData");

}

reloadData 在表完成重新加载其数据之前不会结束.因此,当第二个 NSLog 被触发时,表视图实际上已经完成了对数据的请求.

reloadData doesn't end before the table has finish reload its data. So, when the second NSLog is fired, the table view has actually finish asking for data.

我已经将 UITableView 子类化,以便在 reloadData 之前和之后向委托发送方法.它就像一个魅力.

I've subclassed UITableView to send methods to the delegate before and after reloadData. It works like a charm.