UICollectionView reloadData在iOS 7中无法正常运行 [英] UICollectionView reloadData not functioning properly in iOS 7

查看:312
本文介绍了UICollectionView reloadData在iOS 7中无法正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在更新我的应用程序以在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.

还有其他人看过这个吗?

Has anyone else seen this?

推荐答案

强制执行此操作主线程:

Force this on the main thread:

dispatch_async(dispatch_get_main_queue(), ^ {
    [self.collectionView reloadData];
});

这篇关于UICollectionView reloadData在iOS 7中无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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