I have a very basic CoreData backed iPhone application. After I forced the app to generate the sqlite file, I took it and prepopulated it with one record to test loading it into tableview.
I've hit a snag, though, because CoreData doesn't seem to be finding the row in the table.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
The first function always returns one and the second function always returns zero. Since the tableview thinks there are no rows, it never hits cellForRowAtIndexPath, so none of my data is loaded.
I can, however, see my table structure in viewDidLoad with the following code:
if(!managedObjectContext){
managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Assessment" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
for (NSPropertyDescription *property in entity)
{
NSLog(@"%@", property.name);
}
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
[request release];
Now, it strikes me that nothing in the rest of my code ever generates an NSFetchRequest because I never hit cellForRowAtIndex. But I also based most of this code on the Recipe example, and it looks like it loads in the same way (and it actually works).
I'm sure I'm missing something obvious here, can someone point me in the right direction?
The code can be found in it's entirety here.