Getting sectionNameKeyPath to work with CoreData/UITableViewController
- In my AppDelegate I create an NSFetchedResultsController with sectionNameKeyPath set to @"group".
- In viewWillAppear in my TableViewController I performFetch, then call a method called findGroups.
- findGroups does some complicated analysis of the entire dataset to identify groups, then sets the "group" transient property on each object to the correct string value. I can see with NSLog that these are all set correctly and in coherent groups.
But, tinker as I may, my cells are shown in a singl开发者_如何学JAVAe section with the title of the first group. Any ideas?
Have you implemented:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [[fetchedResultsController sections] count];
}
You also have the problem that the sectionNameKeyPath can't be a transient value.
Actually, this worked fine for me by adding a step 4: [self.tableView reloadData];
精彩评论