我的获取有一个大问题,真的不知道我的错误在哪里。
问题出在 viewWillAppear 函数中,我将我的东西加载到 tableView 中,这是代码:
NSNotificationCenter * theCenter = [NSNotificationCenter defaultCenter];
NSFetchedResultsController *theController = [[NSFetchedResultsController alloc] initWithFetchRequest:self.fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];
NSError *theError = nil;
theController.delegate = self;
//everything fine
self.fetchedResultsController = theController;
//program stops
if(![self.fetchedResultsController performFetch:&theError]) {
NSLog(@"viewDidLoad: %@", theError);
}
[theCenter addObserver:self
selector:@selector(managedObjectContextDidSave:)
name:NSManagedObjectContextDidSaveNotification
object:nil];
[tableView reloadData];
fetchedResultController 有一些问题,但我真的不知道是什么样的。错误信息是:
2013-10-22 10:53:04.750 myAppName[508:c07] CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. *** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0] with userInfo (null)
编辑:NSFetcheResultsControllerDelegate:
- (void)controllerDidChangeContent:(NSFetchedResultsController *)inController {
[tableView endUpdates];
}