Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Diary App Using Core Data Listing Data using NSFetchedResultsController Section Headers and Table View Cells

Rashii Henry
Rashii Henry
16,433 Points

Section Headers and Table View Cells

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { //grab the section info from our fetched results controller.

id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][sectionInfo];

return [sectionInfo name];

}

i get an error on the line where i try to fetch the section info. the error says "Expected method to read dictionary element not found on object of type NSArray"

1 Answer

Stone Preston
Stone Preston
42,016 Points

you need to use [self.fetchedResultsController sections][section] not [self.fetchedResultsController sections][sectionInfo]

id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];
Rashii Henry
Rashii Henry
16,433 Points

I understand. But is it because inside the method declaration the name of the NSInteger that is returned is named section?

hey stone, would you happen to know that id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section]; exactly does? I haven't seen the [section] syntax before