performBatchUpdates:completion: 中的 reloadData: 不调用 cellForItemAtIndexPath: [英] reloadData in performBatchUpdates:completion: does not call cellForItemAtIndexPath:

查看:51
本文介绍了performBatchUpdates:completion: 中的 reloadData: 不调用 cellForItemAtIndexPath:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以当我注意到这段代码时,我正在玩我的 UITableView:

So I was playing around my UITableView when I noticed that this code:

[self performBatchUpdates:^{
    [self reloadData];
} completion:^(BOOL finished) {}];

不会导致cellForItemAtIndexPath:被调用,只会调用UICollectionViewFlowLayoutsizeForItemAtIndexPath.

does not lead to cellForItemAtIndexPath: being called, only sizeForItemAtIndexPath of UICollectionViewFlowLayout is called.

有人知道为什么会这样吗?

Does anybody have any idea why this is happening?

我确切地知道 reloadData 中发生了什么,但这与此不同.

I know exactly what happens in reloadData but this is different from that.

推荐答案

来自 reloadData 的文档:不应在插入或删除行的方法中调用它,尤其是在动画块中通过调用 beginUpdates 和 endUpdates 实现."也许这也适用于 performBatchUpdates.

From the docs of reloadData: "It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to beginUpdates and endUpdates." Perhaps this also applies to performBatchUpdates.

这篇关于performBatchUpdates:completion: 中的 reloadData: 不调用 cellForItemAtIndexPath:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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