尝试插入新单元格时,在UICollectionView中出现NSInternalInconsistencyException

时间:2013-09-26 20:22:51

标签: ios uicollectionview

我正在尝试将新单元格插入_myMusicCollectionView。 Datasource是SharedAppDelegate.myMusics数组:

[_myMusicsCollectionView performBatchUpdates:^{
                                [SharedAppDelegate.myMusics addObject:c.item];
                                [_myMusicsCollectionView insertItemsAtIndexPaths:[[NSArray alloc] initWithObjects:[NSIndexPath indexPathForRow:SharedAppDelegate.myMusics.count-1 inSection:0], nil]];
                            } completion:^(BOOL finished) {
                                [_musicStoreCollectionView reloadItemsAtIndexPaths:[[NSArray alloc] initWithObjects:indPath, nil]];
                            }];

我得到了:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for index path for global index 805306367 when there are only 1 items in the collection view'

我哪里错了?

1 个答案:

答案 0 :(得分:-1)

正如您可以阅读错误原因,您正在访问索引为805306367的单元格。可能这意味着SharedAppDelegate.myMusics.count-1为负数或indPath包含错误值。