1.在dataSource賦值的時候:
注:model.mediumArr為加載進來的新數據源
NSMutableArray*indexPaths = [[NSMutableArray alloc] init];
?for ( inti =0; i < model.mediumArr.count; ?i ++) {
? ? ? ? ? NSIndexPath *indexPath = [NSIndexPath indexPathForRow: self.dataSource.count+ i inSection: 0];
? ? ? ? ? ?[indexPaths addObject: indexPath];
}
if (indexPaths.count > 0) {
? ? ?[self.dataSource addObjectsFromArray:model.mediumArr];
? ? ?[self.collectionView insertItemsAtIndexPaths:indexPaths];
? ? ?[UIView performWithoutAnimation:^{
? ? ? ? ? ?[self.collectionView reloadItemsAtIndexPaths:indexPaths];
? ? ?}];
}
2.如果項目涉及到collectionView的滑動優化,在需要只調用reloadData的時候:添加如下動畫。
[UIView animateWithDuration:0 animations:^{
? ? ? [self.collectionView performBatchUpdates:^{
? ? ? ? ? ? [self.collectionView reloadData];
? ? ? ?} completion: nil];
}];