20

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.

How can I customize reloadSections animation? I definitely saw this in apps on the App Store.

4

3 回答 3

31

就这样做:

[self.collectionView performBatchUpdates:^{
    [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];
于 2013-10-09T13:35:56.707 回答
26

斯威夫特 3 版本:

collectionView.performBatchUpdates({
    let indexSet = IndexSet(integer: 0)
    self.collectionView.reloadSections(indexSet)
}, completion: nil)
于 2016-10-27T16:58:01.157 回答
2

这篇文章值得一读:http: //victorlin.me/posts/2016/04/29/uicollectionview-invalid-number-of-items-crash-issue

TLDR:

所以结果是 performBatchUpdates在调用给定闭包之前先调用 collectionView(:numberOfItemsInSection:) 以了解项目编号。接下来,它调用闭包,最终,它再次调用 collectionView(:numberOfItemsInSection:) 来检查数字。这里是抛出断言异常的地方。

于 2016-08-18T13:29:36.457 回答