ios - CoreData Related data in a tableviewcell -
ios - CoreData Related data in a tableviewcell -
i working on project related entities in coredata. want have tableview cells show attributes of records related entity, struggling find way this.
here's basics:
my custom tableviewcell has 5 things:
uilabel *eventtime uilabel *person1name uiimageview *person1image //storing string uilabel *person2name uiimageview *person2image //storing string
event entity has time, person1name, , person2name attributes , to-many relationship person entity.
person entity has string attributes name , image , to-many relationship events entity.
events have 2 related person records.
persons affiliated many events.
in cellforrowatindexpath, how configure cell related person attributes show each event?
i playing this:
eventstableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"eventcell" forindexpath:indexpath]; event *event = [self.fetchedresultscontroller objectatindexpath:indexpath]; nsset *persons = event.eventpersons; //eventpersons nsset in nsmanagedobject subclass… // configure cell... (player* p in persons) { if (p.firstname == event.person1name) { cell.player1namelabel.text = p.firstname; cell.player1imageview.image = [uiimage imagewithcontentsoffile:p.playerimage]; } else if (p.firstname == event.person2name) { cell.player2namelabel.text = p.firstname; cell.player2imageview.image = [uiimage imagewithcontentsoffile:p.playerimage]; } }
but may have multiple people same first name, fails work in cases. don't want store bunch of duplicate info in event entity comparing records , prefer more elegant way grab attributes of 2 related person records in each cell.
thanks.
you have duplicate info in storage of names. problem aren't unique.
so, alter them unique (i.e. utilize different identifier name) or utilize different method of recording first , sec (i.e. utilize ordered relationship).
ios uitableview core-data relationship
Comments
Post a Comment