我尝试将非某些核心数据对象与核心数据对象混合,我使用 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