I have noticed that a problem in my app is caused because the Datasource methods of the UITableView
are called before viewDidLoad
.
The problem is that the UITableView
doesn't have the correct amount of rows, it gets the amount of rows from the NSFetchedResultsController
but the performFetch
"function" for that is called in the viewDidLoad
method which for some reason is called after the Datasource methods.
Here's the source of the two important methods:
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.allowsSelectionDuringEditing = NO;
self.tableView.editing = YES;
self.title = [NSString stringWithFormat:@"%@", [[game valueForKey:@"title"] description]];
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
How do I get past this problem?