私はを使用していて、からデータをロードするcore data
を持っています。これはであり、モーダルビューを3回ロードすると、でクラッシュします。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
サンプルプロジェクトに従いましたが、コードはほぼ同じに見えます。モーダルビューを数回ロードした後、クラッシュするのはなぜですか?