Ios 性能更新上的UICollectionView崩溃
我想不出这次车祸的原因是什么Ios 性能更新上的UICollectionView崩溃,ios,objective-c,crash,uicollectionview,Ios,Objective C,Crash,Uicollectionview,我想不出这次车祸的原因是什么 Incident Identifier: BF4459C1-B97D-448E-AAE0-4DA6A1E4731C CrashReporter Key: E725A626-A25C-4923-8383-0BC7ECA7DADE Hardware Model: iPhone6,1 Process: SampleProject [480] Path: /var/containers/Bundle/Application
Incident Identifier: BF4459C1-B97D-448E-AAE0-4DA6A1E4731C
CrashReporter Key: E725A626-A25C-4923-8383-0BC7ECA7DADE
Hardware Model: iPhone6,1
Process: SampleProject [480]
Path: /var/containers/Bundle/Application/458F9694-4BDA-4207-8C90-C2192520F8E2/SampleProject.app/SampleProject
Identifier: com.mydomain.SampleProject
Version: 1.3.0 (1.3.0.36)
Code Type: ARM-64
Parent Process: ??? [1]
Date/Time: 2017-05-17T04:11:03Z
Launch Time: 2017-05-17T04:06:51Z
OS Version: iPhone OS 10.3.1 (14E304)
Report Version: 104
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0xfffffffffffffff8
Crashed Thread: 0
Application Specific Information:
Selector name found in current argument registers: _setLayoutAttributes:atGlobalItemIndex:
Thread 0 Crashed:
0 UIKit 0x000000018de7d38c -[UICollectionViewData _setLayoutAttributes:atGlobalItemIndex:] + 80
1 UIKit 0x000000018de7ac94 __45-[UICollectionViewData validateLayoutInRect:]_block_invoke + 1892
2 UIKit 0x000000018de79f68 -[UICollectionViewData validateLayoutInRect:] + 1492
3 UIKit 0x000000018de8023c -[UICollectionViewData layoutAttributesForElementsInRect:] + 264
4 UIKit 0x000000018de7dbc0 -[UICollectionView _updateVisibleCellsNow:] + 548
5 UIKit 0x000000018dfea058 -[UICollectionView _setupCellAnimations] + 28
6 UIKit 0x000000018dff459c -[UICollectionView _beginUpdates] + 44
7 UIKit 0x000000018e72c8c0 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:] + 256
8 UIKit 0x000000018e72c79c -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:] + 92
9 UIKit 0x000000018e72c720 -[UICollectionView _performBatchUpdates:completion:invalidationContext:] + 80
10 UIKit 0x000000018dff4558 -[UICollectionView performBatchUpdates:completion:] + 60
11 SampleProject 0x000000010002a4b8 -[InvitesDataSource didDeleteDataAtIndexes:loadDataAtIndexes:] (InvitesDataSource.m:50)
12 SampleProject 0x0000000100092f58 -[DialogsController _didReceiveOldestInvites:] (DialogsController.m:311)
13 SampleProject 0x0000000100092500 -[DialogsController _didReceiveOldestDialogs:ofType:] (DialogsController.m:248)
14 SampleProject 0x000000010004aad8 -[DialogsController(Notifications) dialogListDidReceived:] (DialogsController+Notifications.m:94)
crashlog中提到的一段代码非常平静:
- (void)didDeleteDataAtIndexes:(NSIndexSet *)deleted loadDataAtIndexes:(NSIndexSet *)loaded {
[self.collectionView performBatchUpdates:^{
[deleted enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
[self.collectionView deleteItemsAtIndexPaths:[self _indexPathsForIndex:idx]];
}];
[loaded enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
[self.collectionView insertItemsAtIndexPaths:[self _indexPathsForIndex:idx]];
}];
} completion:^(BOOL finished) {
[self.collectionView reloadData];
}];
}
要插入、删除或移动单个节或项,必须执行以下步骤: 更新数据源对象中的数据。 调用集合视图的相应方法以插入或删除节或项
在通知集合视图任何更改之前,更新数据源是至关重要的。集合视图方法假定数据源包含当前正确的数据。如果没有,则collection view可能从您的数据源接收到错误的项目集,或者请求不存在的项目,从而使您的应用程序崩溃。这可能会发生,因为您还需要确保使用CollectionView删除和插入节。当您尝试在不存在的节中插入项目时,将发生此崩溃 Preform Batch Update不知道您在X+1,X处插入项目时打算添加部分X+1。而您尚未在中添加该部分 确保使用插入和删除节:
您检查过了吗?谢谢,我会仔细检查你确定这是基于崩溃报告的问题吗?你可以在调试模式下检查。首先需要更新数据源,然后调用update,否则在更新视图之前,它不会在集合数据中发现任何更改。假设您正在尝试在update中添加一行,以便它将尝试查找添加到数据源中的任何数据,否则它将通过该数据向CV添加单元格。所以,首先在数据源中进行添加/删除更改,然后进行更新。谢谢