问题描述
我一直在更新我的应用程序以在 iOS 7 上运行,这在大多数情况下进展顺利.我在多个应用程序中注意到 UICollectionViewController
的 reloadData
方法不像以前那样表现得很好.
I've been updating my apps to run on iOS 7 which is going smoothly for the most part. I have noticed in more than one app that the reloadData
method of a UICollectionViewController
isn't acting quite how it used to.
我将加载UICollectionViewController
,像往常一样用一些数据填充UICollectionView
.这在第一次很有效.但是,如果我请求新数据(填充 UICollectionViewDataSource
),然后调用 reloadData
,它将查询 numberOfItemsInSection
和 的数据源numberOfSectionsInCollectionView
,但它似乎没有正确调用 cellForItemAtIndexPath
的次数.
I'll load the UICollectionViewController
, populate the UICollectionView
with some data as normal. This works great on the first time. However if I request new data (populate the UICollectionViewDataSource
), and then call reloadData
, it will query the data source for numberOfItemsInSection
and numberOfSectionsInCollectionView
, but it doesn't seem to call cellForItemAtIndexPath
the proper number of times.
如果我将代码更改为仅重新加载一个部分,那么它将正常运行.改变这些对我来说没有问题,但我认为我不应该这样做.reloadData
应根据文档重新加载所有可见单元格.
If I change the code to only reload one section, then it will function properly. This is no problem for me to change these, but I don't think I should have to. reloadData
should reload all visible cells according to the documentation.
有其他人看到过吗?
推荐答案
在主线程上强制执行:
dispatch_async(dispatch_get_main_queue(), ^ {
[self.collectionView reloadData];
});
这篇关于UICollectionView reloadData 在 iOS 7 中无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!