Trouble with Core Data


ok trying grab nsmutable set. yes have previous post on different. have player entity , team entity. set 1 many relationship... on different view controller added players team. trying teams players show on table view... fetching information follows.

code:
     - (nsfetchedresultscontroller *)fetchedresultscontroller {     if (_fetchedresultscontroller != nil) {         return _fetchedresultscontroller;     }          nsstring *entityname = @"team";      nslog(@"setting fetched results controller entity named %@", entityname);          // 2 - request entity          nsfetchrequest *request = [nsfetchrequest fetchrequestwithentityname:entityname];          appdelegate *delegate = [[uiapplication sharedapplication] delegate];     _managedobjectcontext = delegate.managedobjectcontext;          // 4 - sort      request.sortdescriptors = [nsarray arraywithobject:[nssortdescriptor sortdescriptorwithkey:@"players"                                                                                      ascending:no                                                                                       selector:@selector(localizedcaseinsensitivecompare:)]];          // 5 - fetch     self.fetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:request                                                                         managedobjectcontext:self.managedobjectcontext                                                                           sectionnamekeypath:nil                                                                                     cachename:nil];     _fetchedresultscontroller.delegate = self;          return _fetchedresultscontroller; }    
then on cell row @ index path setting player object fetched results follows
code:
          player *p = [_fetchedresultscontroller objectatindexpath:indexpath]; then, setting title of cell so. 
code:
      cell.textlabel = p.firstname; 
i getting error
code:
 reason: 'to-many key not allowed 
i wondering doing wrong???
 

as you've got shown fetchrequest returning teams not players.

fetchedresultscontroller ask entity interested in. if tableview showing list of "players" set fetchedresultscontroller entity 'players' not 'team'.

can use other settings of fetch request filter down results interested in. find it's easier build each view piece meal. 1 bit working refine, refine, refine.

refinement @ predicate. have @ nspredicate. fetched results use predicate see if should include entities in results.so in case players team equal team focusing on this.

code:
nspredicate *predicate = [nspredicate predicatewithformat:@"team '%@'", team];
with fetched results sorting purely ordering of objects returned. should using players name or number sort players.

if had fetched results set let know if new player added team, delegate methods called prompt tableview update.

btw: have keep in same thread. helps people understand what's been discussed.
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

Rogue - the old text based game. I can't find it!

RAID in Early 2009 Mac Pro

NBC Releases Summer Olympics iOS Apps, Offering Livestreaming of All 302 Events