運行崩潰時,我使用的是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