I was used NSArray to read data in Core Data and show them to table view cell. there is no problems.
But when I tried to use NSFetchedResultsController, I got error as below if I scroll table view, what do I have to pay attention?
my code as below
But when I tried to use NSFetchedResultsController, I got error as below if I scroll table view, what do I have to pay attention?
Code:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
my code as below
Code:
- (NSFetchedResultsController *)fetchedResultsController {
if (fetchedResultsController_ != nil) {
return fetchedResultsController_;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:RHYME_ENTITY inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"code" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:20];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"code like %@", @"???001"];
[fetchRequest setPredicate:filter];
NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil cacheName:@"Root"];
self.fetchedResultsController = theFetchedResultsController;
self.fetchedResultsController.delegate = self;
return self.fetchedResultsController;
}