I have a tableview which needs to show all the different destination entities from the different relationships. To keep it simple, let’s look at one relationship, the one from the entity Operation to Goal, relationshipname: goal (inverse: operationalisation)
I’m wondering how to fill the cells
This is what I have:
- (void)viewWillAppear:(BOOL)animated{
goals = [[NSArray alloc] init];
goals = [[self.operation valueForKeyPath:@"goal.goalNaam"] allObjects] ;
}
and
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
}
if(indexPath.section == 2){
Goal *goal = (Goal*)[goals objectAtIndex:indexPath.row];
cell.textLabel.text = goal.goalNaam;
}
// Configure the cell...
return cell;
}
Im wondering this is the way to do it. Simulator jams but is not giving an error..
are you sure you are using a 1:n relationship between Operation and Goal? I think I do not understand your question correctly. Shouldn’t have one Operation multiple Goals and each goal has an attribute
goalNaam? And if it would be like that, than the Operation model would contain a NSSet of associatedGoalobjects which could be retrieved easily.Cheers,
anka