ios - Core Data: Can a NSPredicate in fetchResultsController return multiple objects for each row, into my Table View? -
in other words,
can fetchedresultscontroller return array of arrays? or array of nssets?
code bellow example, of i'm trying do. possible?
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { //... nsset *objects = [_fetchedresultscontroller objectatindexpath:indexpath]; //... }
the reason i'm doing this, is: if user swipes cell, , deletes it. need objects row deleted. , need display data on cell, calculation made on clocks day/row.
here's core data model:
each row must contain clock objects, given day, based on it's clockin property. clockin nsdate object. 1 row should represent 1 day.
could figuring out predicate this? possible?
also, i'm using sections in table view. these out of question. there 1 solution rather no go for, wich create year, month , day, entities. fix. seems odd need that, considering clockin property should give me need...
thank you!
you can accomplish in few lines of code tlindexpathtools subclassing tlindexpathcontroller
, alternative nsfetchedresultscontroller
. have not tested this, here mockup of like:
#import <tlindexpathcontroller.h> @interface groupedindexpathcontroller : tlindexpathcontroller @end #import "groupedindexpathcontroller.h" #import "tlindexpathsectioninfo.h" @implementation groupedindexpathcontroller - (void)setdatamodel:(tlindexpathdatamodel *)datamodel { nsmutablearray *items = [[nsmutablearray alloc] initwithcapacity:datamodel.numberofsections]; (tlindexpathsectioninfo *sectioninfo in datamodel.sections) { if (sectioninfo.objects) { [items addobject:sectioninfo.objects]; } } tlindexpathdatamodel *groupeddatamodel = [[tlindexpathdatamodel alloc] initwithitems:items andsectionnamekeypath:nil andidentifierkeypath:nil]; [super setdatamodel:groupeddatamodel]; } @end
what you'd set index path controller's fetch request sectionnamekeypath
set property want group by. when fetch performed, parent class generate data model organized sections. above code overrides datamodel
property setter, mapping sections single section of grouped objects like:
sectioned data model
section 0 managed object 0.0 managed object 0.1 managed object 0.2 section 1 managed object 1.0 managed object 1.1
grouped data model
section 0 [managed object 0.0, managed object 0.1, managed object 0.2] [managed object 1.0, managed object 1.1]
this grouped data model passed super's datamodel
property setter. table view controller ever see grouped data model. sectioned data model internal groupedindexpathcontroller
. if fetch results change, groupedindexpathcontroller
report updates grouped data model through controller:didupdatedatamodel:
delegate method , tltableviewcontroller
perform batch updates automatically.
tlindexpathtools provides several sample projects, core data example demonstrates how integrate core data. you'd need supply instance of groupedindexpathcontroller
instead of standard tlindexpathcontroller
.
you mentioned table uses sections. if can elaborate can modify above fit specific requirements.
Comments
Post a Comment