objective-c 带有动画的 UICollectionView reloadSections
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19273447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UICollectionView reloadSections with animation
提问by Sergey
I'd like to reload UICollectionView with some interesting animation. In UITableView there's a method called reloadSections:withRowAnimation.
But in UICollectionView there's just reloadSections.
我想用一些有趣的动画重新加载 UICollectionView。在 UITableView 中有一个方法叫做reloadSections:withRowAnimation. 但是在 UICollectionView 中只有reloadSections.
How can I customize reloadSections animation? I definitely saw this in apps on the App Store.
如何自定义 reloadSections 动画?我肯定在 App Store 上的应用程序中看到了这一点。
回答by Fab1n
Just do it like that:
就这样做:
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];
回答by Mark Bridges
Swift 3 version:
斯威夫特 3 版本:
collectionView.performBatchUpdates({
let indexSet = IndexSet(integer: 0)
self.collectionView.reloadSections(indexSet)
}, completion: nil)
回答by cldrr
This article here is worth a read: http://victorlin.me/posts/2016/04/29/uicollectionview-invalid-number-of-items-crash-issue
这里的这篇文章值得一读:http: //victorlin.me/posts/2016/04/29/uicollectionview-invalid-number-of-items-crash-issue
TLDR:
域名注册地址:
So it turned out performBatchUpdates calls collectionView(:numberOfItemsInSection:) first before call the given closure to know the item numbers. Next, it calls the closure, and eventually, it calls collectionView(:numberOfItemsInSection:) again to check the number. And here is where the assertion exception thrown.
所以结果是 performBatchUpdates在调用给定的闭包之前先调用 collectionView( :numberOfItemsInSection:) 以了解项目编号。接下来,它调用闭包,并最终再次调用 collectionView(:numberOfItemsInSection:) 来检查数字。这是抛出断言异常的地方。

