我有一个TableView控制器类,它使用提取的结果控制器来显示从核心数据模型中获取的“患者”实体列表。该表的各个部分取自一个名为“位置”的患者属性。下面是提取请求的排序描述:严重的应用程序错误
NSSortDescriptor *locationDescriptor = [[NSSortDescriptor alloc] initWithKey:@"location" ascending:YES];
NSSortDescriptor *lastNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:locationDescriptor, lastNameDescriptor, nil];
下面是FRC的初始化代码:
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"location" cacheName:@"List"];
当我想添加一个新的“病人”实体 - 我点击添加按钮然后将“添加新患者”视图控制器推送到导航堆栈。
我加的第一个病人工作正常。
如果我添加了第二个病人 - 应用程序有时会出现以下错误崩溃:
2010-03-22 14:42:05.270 Patients[1126:207] Serious application error. Exception was caught during Core Data change processing: * -[NSCFArray insertObject:atIndex:]: index (1) beyond bounds (1) with userInfo (null) 2010-03-22 14:42:05.272 Patients[1126:207] * Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray insertObject:atIndex:]: index (1) beyond bounds (1)'
这似乎只如果患者的增加了一个位置发生(如果未添加该位置,然后默认为'未知')。这似乎也与排序的位置有关。例如,如果第一个患者位置=病房14,第二病房= 9,那么它肯定崩溃。
我想知道如果这是怎么回事,我要求获取的结果控制器排序节名?
这个错误是驱使我坚果,我只是无法弄清楚。任何帮助将不胜感激!
这解决了我的问题! – 2013-01-09 13:21:51
这仍然需要在iOS 8? – SAHM 2014-10-07 15:46:04