我使用的 TableViewController 类与您在 Xcode 中启动新的 Master-Detail 应用程序项目时创建的类非常相似。因此,我使用在 TableViewController 类中预填充的相同代码供我自己使用。但是,我遇到了运行时崩溃,我不知道为什么。我在我的应用程序的另一类中使用了这个确切的代码,它运行良好。
- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName"Binder" inManagedObjectContext:[appDelegate managedObjectContext]];
[fetchRequest setEntity:entity];
// Edit the sort key as appropriate.
//NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey"timeStamp" ascending:NO];
//NSArray *sortDescriptors = @[sortDescriptor];
//[fetchRequest setSortDescriptors:sortDescriptors];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
//This is where it crashes
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[appDelegate managedObjectContext] sectionNameKeyPath:nil cacheName"Master"];
//End crash
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _fetchedResultsController;
}
我不确定这里还包括哪些其他代码片段。崩溃发生时输出没有告诉我任何信息,Xcode 跳转到主线程的这一部分:
libsystem_kernel.dylib`__kill:
0x972893b0: movl $786469, %eax
0x972893b5: calll 0x9728b4c2 ; _sysenter_trap
0x972893ba: jae 0x972893ca ; __kill + 26 //This is highlighted
0x972893bc: calll 0x972893c1 ; __kill + 17
0x972893c1: popl %edx
0x972893c2: movl 27739(%edx), %edx
0x972893c8: jmpl *%edx
0x972893ca: ret
0x972893cb: nop
有什么想法吗?
谢谢
Best Answer-推荐答案 strong>
感谢@flashfabrixx,问题是我没有使用排序描述符,而在使用NSFetchedResultsController 时需要它们。一旦我重新添加了排序描述符,一切都运行良好。
关于ios - 核心数据 - 创建 NSFetchedResultsController 时的运行时崩溃,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/15711272/
|