attempt to scroll to invalid ind

2019-11-26  本文已影响0人  子溟666

如果被滚动到的cell已经被删除,则会出现这个错误,解决办法:添加一个判断,如果此时cell不是最后的cell则不滚动。

[self.collectionView performBatchUpdates:^{

        [self.collectionView insertItemsAtIndexPaths:@[indexPath2]];

    }completion:^(BOOLfinished) {

        // 动画延迟,如果要滚动到的cell不是最后的cell,则不滚动,因为有可能已经被删除

        if(indexPath2.row!=self.dataSource.count-1) {

            return;

        }

        [self.collectionView scrollToItemAtIndexPath:indexPath2 atScrollPosition:(UICollectionViewScrollPositionRight) animated:YES];

    }];

上一篇 下一篇

猜你喜欢

热点阅读