CoreData에서 관련된 엔티티가있는 프로젝트에서 작업하고 있습니다. 관련 엔티티의 레코드 속성을 표시하는 셀을 가진 테이블 뷰를 원하지만이 작업을 수행하는 좋은 방법을 찾기 위해 고심하고 있습니다.CoreData 테이블 뷰 셀의 관련 데이터
여기에 기초를이다 :
내 사용자 정의 TableViewCell은 다섯 가지가 있습니다
UILabel *eventTime
UILabel *person1Name
UIImageView *person1Image //storing a string
UILabel *person2Name
UIImageView *person2Image //storing a string
이벤트 엔티티, person1Name을 시간을 가지고, 그리고 person2Name 속성 및 내 사람 엔티티에 일대 다 관계.
Person 엔티티에는 name 및 image에 대한 문자열 속성과 내 Events 엔티티에 대한 다수 관계가 있습니다.
이벤트에는 항상 두 개의 관련 개인 레코드가 있습니다.
인물은 많은 사건과 관련이 있습니다.
내 cellForRowAtIndexPath에 관련 인물 속성이 각 이벤트에 표시되도록 셀을 구성하는 방법은 무엇입니까?
EventsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EventCell" forIndexPath:indexPath];
Event *event = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSSet *persons = event.eventPersons; //eventPersons is the NSSet in the NSManagedObject subclass…
// Configure the cell...
for (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];
}
}
을하지만 같은 이름을 가진 여러 사람이있을 수 있습니다, 그래서 이것은 모든 경우에 제대로 작동하지 :
나는이 함께 연주했다. 레코드 비교를 위해 이벤트 엔티티에 중복 정보를 저장하는 것을 원하지 않으며 각 셀에있는 두 개의 관련 사람 레코드의 속성을 가져 오는보다 우아한 방법을 선호합니다.
감사합니다.