问题 UICollectionView:断言失败 - [UICollectionView _endItemAnimations]


我在我的应用中收到此错误:

***断言失败 -[UICollectionView _endItemAnimations],/ SourceCache/UIKit/UIKit-2372/UICollectionView.m:2801

它发生在我的身上 -controllerDidChangeContent: 这条线上的方法:

[self.collectionView performBatchUpdates:^{...}];

有谁知道是什么原因造成的?我的代码是基于密切关注的 https://gist.github.com/4440c1cba83318e276bb 而我却不知所措。

谢谢!


8873
2017-12-07 19:46


起源



答案:


这些类型的断言被抛出作为异常。在try / catch中包装批处理更新并转储异常描述。它会告诉你它与你的通话有什么不同。

换一种说法:

    @try
    {
        [self.collectionView performBatchUpdates:^{...}];
    }
    @catch (NSException *except)
    {
        NSLog(@"DEBUG: failure to batch update.  %@", except.description);
    }

9
2018-05-09 15:16



啊,我在斯威夫特......多么不幸...... - Eonil
调试的好选择。 - kelin


答案:


这些类型的断言被抛出作为异常。在try / catch中包装批处理更新并转储异常描述。它会告诉你它与你的通话有什么不同。

换一种说法:

    @try
    {
        [self.collectionView performBatchUpdates:^{...}];
    }
    @catch (NSException *except)
    {
        NSLog(@"DEBUG: failure to batch update.  %@", except.description);
    }

9
2018-05-09 15:16



啊,我在斯威夫特......多么不幸...... - Eonil
调试的好选择。 - kelin


我打赌这是因为你的

-controllerDidChangeContent

正在后台线程中多次调用,而当另一个线程调用时,performBatchUpdates仍在工作,因此会导致错误的行为。

解决方案 - 尝试将其包装在@synchronized或使用NSLocks


1
2017-12-07 20:08



它绝对是在主线程上调用的,所以这不是问题


问题是没有在查看didDisappear时将FRC代表设置为nil。


1
2017-12-08 00:32



干杯!就是这样!在viewDidDisappear上将FRC设置为nil并重新分配给viewWillAppear的self,解决了我的类似问题。 - So Over It
FRC代表什么? : - | - Kalle
@Kalle:FRC =获取结果控制器 - AlexR