iphone - NSFetchedResultsController with a one-to-many relationship -
i'm looking display data core data model in uitableviewcontroller
. model has 2 entities, one-to-many relationship. want items many entity rows, broken down sections one. in event no rows exist, still want section header display.
i have working nsfetchedresultscontroller
table working many table only, need expand one-to-many relationship. i'm having no luck making work, , haven't found examples on how this.
the table display items, not subset.
any suggestions?
since didn't provide details model objects using, example use following model.
the first thing suggest doing @ documentation nsfetchedresultscontroller
, initwithfetchrequest:managedobjectcontext:sectionnamekeypath:cachename:
. tells need know fetching data sections.
the important part first sort descriptor must return similar order sectionnamekeypath
.
nsfetchrequest *fetchrequest = [nsfetchrequest fetchrequestwithentityname:@"book"]; nssortdescriptor *librarysort = [[nssortdescriptor alloc] initwithkey:@"name" ascending:yes]; nssortdescriptor *booksort = [[nssortdescriptor alloc] initwithkey:@"title" ascending:yes]; [fetchrequest setsortdescriptors:@[librarysort, booksort]]; nsfetchedresultscontroller *controller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fetchrequest managedobjectcontext:context sectionnamekeypath:@"library.name" cachename:nil];
Comments
Post a Comment