Tuesday, 15 July 2014

ios - Populating a tableview with child objects of parent entity -



ios - Populating a tableview with child objects of parent entity -

i have 2 tableviewcontrollers in navigation controller hierarchy. first contains parent entities, have populated core info entity fetch request. created one-to-many relationship in parent entity kid entity , seem adding kid entities okay. can populate children of parents, can't restrict current parent. have tried using predicates in kid tableview controller fetch request without success.

should using includessubentities , keeping parent entity used in request? if so, utilize delegate protocol in way?

the code below kid tableview. commented-out bits different attempts!

thanks.

- (nsfetchedresultscontroller *)fetchserials { if ( !_fetchserials ) { nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] init]; nsentitydescription *entity = [nsentitydescription entityforname:@"serial" inmanagedobjectcontext:appdelegateptr.managedobjectcontext]; // nspredicate *predicate = [nspredicate predicatewithformat:@"inexercise.name = '%@'", [[smnetworkmodel sharedinstance] selectednarrative]]; // [fetchrequest setpredicate:predicate]; // [fetchrequest setrelationshipkeypathsforprefetching:@[@"inexercise"]]; [fetchrequest setentity:entity]; nssortdescriptor *sortdescriptor = [[nssortdescriptor alloc] initwithkey:@"narrative" ascending:yes]; [fetchrequest setsortdescriptors:@[sortdescriptor]]; _fetchserials = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fetchrequest managedobjectcontext:appdelegateptr.managedobjectcontext sectionnamekeypath:nil cachename:nil]; _fetchserials.delegate = self; nserror *error; if ( ![_fetchserials performfetch:&error] ) nslog(@"fetch error: %@", error.localizeddescription); } homecoming _fetchserials; }

a stupid typo combined shortfall in understanding of new friend core info stopping predicates working.

i had mistakenly thought passed objectids around instead of objects themselves.

uncomment 2 lines involving predicate , alter selectednarrative right property , worked!

ios objective-c

No comments:

Post a Comment