2

UICollectionView crash when performBatchUpdates after reload data.I don't perform any delete or add operation,only refresh data after net request success. code like this

- (void)reloadData:(NSArray *)dataArray {
self.dataSourceArray = dataArray;
[_collectionView reloadData];
[_collectionView performBatchUpdates:nil completion:^(BOOL finished) {
    if ([_collectionView numberOfItemsInSection:0] > 0) {
        [_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
    }
}];

}

function reloadData maybe call twice consecutive and fast,everytime use new data reload collection view. i think somewhere use incorrect with collection view,but i can't find it.

ldward
  • 63
  • 8
  • What is the exception message and what line of code does it crash on? – Paulw11 Mar 10 '17 at 04:37
  • Title is the specific exception message and crash on the last line,that is the block's bracket ; – ldward Mar 10 '17 at 04:52
  • Please add the crash log as it helps to figure out the problem. Additionally you don't need to call batch updates to simply scroll and/or reload data. It is suggested when only insertion or deletion takes place on individual rows. – Rikh Mar 10 '17 at 04:53
  • @Rikh Thanks. I also feel unnecessary call batch updates.But when perform scroll immediately after reload data, frequently can't scroll to the right item,so i use batch updates to fix that. – ldward Mar 10 '17 at 05:32

0 Answers0