ios - How to get one record per section when using NSFetchedResultsController -
i work on ios app uses core data , want display entity using uitableview.
for i'm using nsfetchedresultscontroller. thing trying achieve display each record in it's section. want 1 row per section.
the methods struggling :
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview
and
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section
because want have piece of code when computing numberofsectionsintableview:
{ id <nsfetchedresultssectioninfo> sectioninfo = [[self.fetchedresultscontroller sections] objectatindex:section]; return [sectioninfo numberofobjects]; }
and want have return 1
when computing numberofrowsinsection (and can't pass indexpath.section
to numberofsectionsintableview
). approach in problem/situation? thank you.
well,
obviously, have section have object :
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview { // return number of sections. return self.fetchedresultcontroller.fetchedobjects.count; }
then, have 1 row / section since want
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return 1; }
then in cellforrowatindexpath use indexpath.section rowindex , indexpath.row sectionindex.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nsindexpath * correctedip = [nsindexpath indexpathforrow:indexpath.section insection:0]; id myitem = [self.fetchedresultcontroller objectatindexpath: correctedip]; /* ... */ }
Comments
Post a Comment