I have the following code, where I believe the NSFetchRequest
is in fact working, but there is nothing showing in my tableView(peopleList) after the viewWillAppear
runs.
-(void)viewWillAppear:(BOOL)animated{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *moc = [appDelegate managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Person"
inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
NSError *error = nil;
NSLog(@"Count for request is %a", [moc countForFetchRequest:request error:&error]);
personArray = [moc executeFetchRequest:request error:&error];
[peopleList reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier];
}
NSString *cellValue = [personArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
Just in case, my storyboard is hooked up as shown.
My console says "Count for request is 23", making me think that the breakdown is somewhere in getting the array itself to show up in the interface. What needs to happen to get my personArray to show up in peopleList?
Any help is appreciated.