Avn*_*arr 23 objective-c-blocks completionhandler uicollectionview uicollectionviewcell
我需要知道何时重新加载UICollectionView已经完成以便以后配置单元格(因为我不是单元格的数据源 - 其他明智的就是已经完成它...)
我试过像这样的代码
[self.collectionView reloadData];
[self configure cells]; // BOOM! cells are nil
Run Code Online (Sandbox Code Playgroud)
我也试过用
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadData];
} completion:^(BOOL finished) {
// notify that completed and do the configuration now
}];
Run Code Online (Sandbox Code Playgroud)
但是当我重新加载数据时,我正在崩溃.
如何将数据重新加载到集合中,并且只有在完成重新加载后才能重新加载 - 执行特定的完成处理程序
luk*_*war 94
这是由在layoutSubviews期间添加的单元格而不是reloadData引起的.由于layoutSubviews是在reloadData之后的下一个运行循环传递期间执行的,因此您的单元格为空.试着这样做:
[self.collectionView reloadData];
[self.collectionView layoutIfNeeded];
[self configure cells];
Run Code Online (Sandbox Code Playgroud)
我有类似的问题,并以这种方式解决它.
如果你想在你的 collectionView 完成它的 reloadData() 方法后执行一些代码,那么试试这个(Swift):
self.collectionView.reloadData()
self.collectionView.layoutIfNeeded()
dispatch_async(dispatch_get_main_queue()) { () -> Void in
// Put the code you want to execute when reloadData is complete in here
}
Run Code Online (Sandbox Code Playgroud)
这样做的原因是因为调度块中的代码被放在行的后面(也称为队列)。这意味着它正在排队等待所有主线程操作完成,包括 reloadData() 的方法,然后才开始打开主线程。
不支持使用的动画重新加载集合视图reloadData.所有动画都必须使用方法执行,例如
[collectionView deleteItemsAtIndexPaths:indexesToDelete];
[collectionView insertSections:sectionsToInsert];
[collectionView reloadItemsAtIndexPaths:fooPaths];
Run Code Online (Sandbox Code Playgroud)
在performBatchUpdates:街区内.该reloadData方法只能用于粗略刷新,当所有项目被移除并再次布局而没有动画时.
| 归档时间: |
|
| 查看次数: |
31201 次 |
| 最近记录: |