我正在使用core data
,並有一個UITableViewController
加載數據從core data
。這是一個modal view
,如果我第三次加載模態視圖,它會崩潰EXC_BAD_ACCESS
。核心數據:獲取結果控制器導致過度釋放/崩潰
- (NSFetchedResultsController *)fetchedResultsController {
if (fetchedResultsController != nil) {
return fetchedResultsController;
}
// Create and configure a fetch request
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Ride" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// Create the sort descriptors array
NSSortDescriptor *sectionTitle = [[NSSortDescriptor alloc] initWithKey:@"dateStart" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sectionTitle, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
// Create and initialize the fetch results controller
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
self.fetchedResultsController = aFetchedResultsController;
fetchedResultsController.delegate = self;
// Memory management
[aFetchedResultsController release];
[fetchRequest release];
[sectionTitle release];
[sortDescriptors release];
return fetchedResultsController;
}//end
崩潰說,它從該行未來:
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Ride" inManagedObjectContext:managedObjectContext];
這是在viewDidLoad中:
if (managedObjectContext == nil) {
managedObjectContext = [MyAppDelegate instance].managedObjectContext;
}
呈現模式的看法:
History *history = [[[History alloc] init] autorelease];
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:history] autorelease];
[self presentModalViewController:nav animated:YES];
解聘莫代爾:
- (void)done {
[self dismissModalViewControllerAnimated:YES];
}
堆棧跟蹤,讓EXC_BAD_ACCESS:現在
,爲了建立這種觀點與核心數據,我跟着Core Data Books
示例項目和我的代碼看起來幾乎相同。爲什麼在幾次加載模態視圖後會崩潰?
此代碼看起來沒問題,還有其他事情正在進行。如果您認爲這與多次展示模態視圖有關,請檢查以確保在模態視圖被解散時沒有任何內容保留模態視圖。在戰略位置添加一些NSLog語句,並查看對象ID以幫助查看發生了什麼。 – XJones
我只是解僱它使用[self dismissModalViewControllerAnimated:YES]這是一個壞主意嗎?我知道蘋果有時候會有所不同。我沒有看到任何其他可能導致這種情況的事情......但我更新了我的代碼,介紹了我如何提出和解僱。 –
你能發佈崩潰和堆棧跟蹤嗎? – XJones