代码之家  ›  专栏  ›  技术社区  ›  Burak

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

  •  0
  • Burak  · 技术社区  · 11 年前

    我正试图在_myMusicCollectionView中插入一个新单元格。数据源是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 回复  |  直到 11 年前
        1
  •  -1
  •   pNre    11 年前

    正如您在错误原因中所看到的,您正在访问索引为805306367的单元格。也许这意味着 SharedAppDelegate.myMusics.count-1 为负数或 indPath 包含错误的值。