我在UINavigationController
的UITableViewController
的子類中有一個NSFetchedResultsController
。當我運行該應用程序時,前三次訪問視圖(進入該視圖,然後單擊「返回」,然後再次轉到該視圖),所有內容都可以正常運行,但在第四次(總是)時,它會崩潰並顯示以下內容:NSFetchedResultsController initWithFetchRequest拋出EXE-BAD-ACCESS異常
-[NSEntityDescription subentitiesByName]: message sent to deallocated instance 0x8b09c80
任何幫助將不勝感激。
這裏是我的結果控制器吸氣:
- (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;
}
上下文對象被創建一次,整個舉行單身人士的應用程序的生命週期。
我已經檢查確保當視圖控制器得到dealloc
ed時,eventsResultsController_
得到釋放。
在堆棧中,有人告訴我它在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
...
'NSFetchRequest`的`setEntity`方法不會保留它嗎? – 2011-02-04 16:10:34