0

一部の Core Data オブジェクトと Core Data オブジェクトを混在させようとしましたが、これは TLIndexPathTools を使用して行います。

- (TLIndexPathDataModel *)controller:(TLIndexPathController *)controller willUpdateDataModel:(TLIndexPathDataModel *)oldDataModel withDataModel:(TLIndexPathDataModel *)updatedDataModel
{
    NSMutableArray *sectionInfos = [NSMutableArray array];
    TLIndexPathSectionInfo *section0 = [[TLIndexPathSectionInfo alloc] initWithItems:@[@"item1", @"item2"] name:@"section0"];
    [sectionInfos addObject:section0];
    [sectionInfos addObjectsFromArray:updatedDataModel.sections];
    return [[TLIndexPathDataModel alloc] initWithSectionInfos:sectionInfos identifierKeyPath:nil];
}

私は TLIndexPathTableViewController を使用しており、TLIndexPathController を次のようにセットアップします。

- (void)setupIndexPathController
{

    NSFetchRequest *fetchRequest;

    NSString *sectionNameKeyPath;
    if (self.product) {


        fetchRequest = [SubMenus getSubMenusForProduct:self.product];

        sectionNameKeyPath = @"group.name";        


    }else if (self.cartProduct) {

        fetchRequest = [SubMenuProductCart getSubMenusForProductCart:self.cartProduct];

        sectionNameKeyPath = @"group.subMenusGroup.name";

    }


    [TLIndexPathController deleteCacheWithName:@"SubMenuGroupTitles"];

    self.indexPathController = nil;
    self.indexPathController = [[TLIndexPathController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:sectionNameKeyPath identifierKeyPath:nil cacheName:@"SubMenuGroupTitles"];

 NSError *error;
    [self.indexPathController performFetch:&error];
}

このセットアップ メソッドは、オブジェクトを取得して更新するために、viewDidAppear で呼び出されます。

しかし、[self.indexPathController.dataModel itemAtIndexPath:indexPath]; を呼び出すと、私の DidSelectRow メソッドでは、次のクラッシュが発生します。

 CoreData: error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array with userInfo
4

1 に答える 1

0

クラッシュは、空の配列にアクセスしているようです。そのため、クラッシュが発生しないことを確認するために、配列内の nil および 0 より大きいカウントの状態を常にチェックしてください。また、配列にオブジェクトを追加する前に、配列が初期化されているかどうかを確認してください。それ以外の場合、オブジェクトを追加することはありません

于 2014-07-09T16:38:36.743 に答える