在我的UITableViewController類,我有這樣的getter函數的NSFetchResultsControllerEXC_BAD_ACCESS:核心數據,NSFetchedResultsController和numberOfRowsInSection
-(NSFetchedResultsController*) fetchedResultsController {
if (_fetchedResultsController == nil) {
FlipPadAppDelegate* app = (FlipPadAppDelegate*) [[UIApplication sharedApplication] delegate];
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:
[NSEntityDescription entityForName:@"FundClass" inManagedObjectContext:[app managedObjectContext]]];
NSSortDescriptor* sortdesp = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortdesp]];
[fetchRequest setFetchBatchSize:20];
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:[app managedObjectContext]
sectionNameKeyPath:nil
cacheName:@"_Stock"];
_fetchedResultsController.delegate = self;
[fetchRequest release];
[sortdesp release];
NSError *error;
if (![[self fetchedResultsController] performFetch:&error]) {
// Handle error
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
}
return _fetchedResultsController;
}
不知何故,當應用程序運行到這一點,
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
id <NSFetchedResultsSectionInfo> sectionInfo = [[[self fetchedResultsController] sections] objectAtIndex:section];
NSLog(@"numberOfRowsInSection %@", [sectionInfo numberOfObjects]);
return [sectionInfo numberOfObjects];
}
它發生火災EXC_BAD_ACCESS
sqllite數據庫中有兩條記錄。
爲什麼這個例外?是否因爲我已將sectionNameKeyPath
設置爲零?或者因爲我沒有將視圖的dataSource設置爲這個控制器?
崩潰日誌說什麼? – WrightsCS