运行崩溃时,我使用的是TableViewController类,很像当你开始在Xcode新的主从应用程序项目时创建的。因此,我使用了预先填充在TableViewController类中的相同代码供我自己使用。然而,我得到一个运行时崩溃,我不知道为什么。我在我的应用的另一个类中使用了这个确切的代码,它完美地工作。核心数据 - 创建NSFetchedResultsController
- (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
有什么想法? 感谢
从什么你认为这是崩溃发生的地步?你有没有设置一个例外断点?如果是,那么在调试控制台中可以看到异常之前,您可能需要继续执行一次或两次。调试堆栈的外观如何,以及调试控制台中的错误消息是什么? –
是的,我设置了一个异常断点。断点设置为“On Catch”,尽管当我将它设置为“On Throw”时它停在同一个点上。但是,当发生异常断点时,我会继续执行,然后停止在我发布的第二位代码处。调试控制台中唯一的是'(lldb)' – Nick
如果将缓存设置为'nil'会发生什么? – Mundi