一部の 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