我有一个tableview需要显示来自不同关系的所有不同目标实体。为了保持它的简单,让我们来看看一个关系,从实体经营到目标,relationshipname一:目标(逆:运作)用目标实体填充tableview
我不知道如何来填补细胞
这是我:
- (void)viewWillAppear:(BOOL)animated{
goals = [[NSArray alloc] init];
goals = [[self.operation valueForKeyPath:@"goal.goalNaam"] allObjects] ;
}
和
- (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;
}
我想知道这是做它的方式。模拟器卡塞,但没有给出错误..
入住的NSLog(@ “的目标:%@”,目标); after goals = [[self.operation valueForKeyPath:@“goal.goalNaam”] allObjects];看看哪个结果会返回。并在目标*目标=(目标*)[目标objectAtIndex:indexPath.row];之后重复此操作。在这个NSlog的结果之一可能为null ...另外,你正好使用indexPath.section == 2而不是indexPath.row == 2? (这是为了以防万一) – frankWhite 2012-08-07 21:30:58
你想用这2个NSLogs完成什么?我无法遵循..而这部分== 2并不重要。只有在连接到操作的目标时才填写本节2。在另一部分,我想要另一个连接到操作的实体。 – Fuzej 2012-08-07 21:42:43
在日志中,您可以看到正确与否的信息。如果你的意思是正确的(例如非空),那么在代码 – frankWhite 2012-08-07 21:49:12