performBatchUpdates:completion: 中的 reloadData: 不调用 cellForItemAtIndexPath: [英] reloadData in performBatchUpdates:completion: does not call cellForItemAtIndexPath:
问题描述
所以当我注意到这段代码时,我正在玩我的 UITableView
:
So I was playing around my UITableView
when I noticed that this code:
[self performBatchUpdates:^{
[self reloadData];
} completion:^(BOOL finished) {}];
不会导致cellForItemAtIndexPath:
被调用,只会调用UICollectionViewFlowLayout
的sizeForItemAtIndexPath
.
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屋!