I work on an iOS app that uses Core Data and I want to display an entity using UITableView.
For that I'm using a NSFetchedResultsController. The thing I am trying to achieve is to display each record in it's section. Basically I want 1 row per section.
The methods that I am struggling with are :
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
and
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
because I want to have this piece of code when computing the numberOfSectionsInTableView:
{
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
and I want to have return 1
when computing the numberOfRowsInSection (and obviously I can't pass indexPath.section
to numberOfSectionsInTableView
).
What is the approach in this problem/situation? Thank you.
well,
Obviously, you will have as much section as you have object :
then, you will only have one row / section since this is what you want
then in the cellForRowAtIndexPath use the indexPath.section as a rowIndex and the indexPath.row as the sectionIndex.