我有一个NSFetchedResultsController
的子类内UITableViewController
一个内部UINavigationController
。 当我运行应用程序,一切完美的作品我访问视图(要它,然后单击“返回”,然后再次将它)前三次,但在第四(总是)符合下列崩溃:
-[NSEntityDescription subentitiesByName]: message sent to deallocated instance 0x8b09c80
任何帮助将非常感激。
这里是我的结果控制器的getter:
- (NSFetchedResultsController*)eventsResultsController {
if (eventsResultsController_ == nil) {
NSFetchRequest *aFetchRequest = [[PADataContext sharedInstance] makeGetAllFetchRequestForEntity:@"PAEvent" sortedBy:@"when" ascending:NO];
// NOTE: crashes on this next line
NSFetchedResultsController *aFetchedResultsContorller = [[NSFetchedResultsController alloc] initWithFetchRequest:aFetchRequest managedObjectContext:[[PADataContext sharedInstance] managedObjectContext] sectionNameKeyPath:@"whenMonth" cacheName:@"AllEvent"];
self.eventsResultsController = aFetchedResultsContorller;
[aFetchedResultsContorller release];
}
return eventsResultsController_;
}
这是我用来创建我的代码NSFetchRequest
:
- (NSFetchRequest*)makeGetAllFetchRequestForEntity:(NSString*)entityName sortedBy:(NSString*)sortString ascending:(BOOL)ascending {
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];
if (sortString != nil) {
// add sorting information
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortString ascending:ascending];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];
}
[entity release];
return fetchRequest;
}
上下文对象被创建一次,整个应用程序的一个单身寿命举行。
我已经检查了保证eventsResultsController_
被释放时的视图控制器获取dealloc
版。
在堆栈中,有人告诉我它在坠毁initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName
方法:
#0 0x00f04057 in ___forwarding___
#1 0x00f03f22 in __forwarding_prep_0___
#2 0x00da1b4d in -[NSFetchedResultsController initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName:]
#3 0x00008c94 in -[PAHistoryListTableView eventsResultsController] at PAHistoryListTableView.m:125
#4 0x00008a5b in -[PAHistoryListTableView loadData] at PAHistoryListTableView.m:52
#5 0x00008a2a in -[PAHistoryListTableView viewDidLoad] at PAHistoryListTableView.m:43
...