表视图与不同的自定义单元格

时间:2012-11-09 14:34:59

标签: objective-c ios

我有一个带有表视图的视图控制器,在故事板中设计,此表视图使用三个不同的自定义单元格,每个单元格用于三个不同的部分。我已经将每个自定义单元格定义为原型单元格,每个单元格使用不同的标识符,并在Xcode中的每个单元格中定义自定义单元格对象,由Interface Builder链接到每个单元格的每个控件。

我已将自定义单元格作为部分顺序,您可以在此处查看。每个标记的正方形都是一个自定义原型单元格。

enter image description here

这是表视图代码:

  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.section==2){
            return 40;
        }else if (indexPath.section==1){
            return 40;
        } else if (indexPath.section==0){
            return 205;

        }

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0){
        return 1;
    } else if (section==1){
        return [[selectedTeam valueForKey:@"jugadores"]count];
    } else if (section==2){
        return [[selectedTeam valueForKey:@"tecnicos"]count];
    }

}

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.section==0){

        NSString *imageService = @"http://backend.exular.net/contenido/";


        imageCell *cellImage = [table dequeueReusableCellWithIdentifier:@"imatge"];

        if (cellImage == nil) {
            cellImage = [[imageCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:@"imatge"];
        }

        cellImage.leagueName.text = [selectedTeam valueForKey:@"nom"];

        NSString *path= [[NSString stringWithFormat:@"%@%@" ,imageService,  [selectedTeam valueForKey:@"img"]] stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

        [cellImage.teamPicture  setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

        imageService=nil;

        return cellImage;

    } else if (indexPath.section==1){


         teamCell *cellTeam = [table dequeueReusableCellWithIdentifier:@"equipo"];

         if (cellTeam == nil) {
             cellTeam = [[teamCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:@"equipo"];
         }

         NSDictionary *teamDic =  [[selectedTeam valueForKey:@"jugadores"] objectAtIndex:indexPath.row];

         cellTeam.name.text = [teamDic valueForKey:@"nom"];

         cellTeam.height.text = [teamDic valueForKey:@"height"];

         cellTeam.number.text = [teamDic valueForKey:@"altura"];

         cellTeam.date.text = [teamDic valueForKey:@"date"];

         cellTeam.position.text = [teamDic valueForKey:@"posicion"];

         return cellTeam;

    } else if (indexPath.section==2){

        NSString *CellIdentifier = @"staff";

        staffCell *cellStaff = [table dequeueReusableCellWithIdentifier:@"staff"];

        if (cellStaff == nil) {
            cellStaff = [[staffCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:@"staff"];
        }

        NSDictionary *staffDic = [[selectedTeam valueForKey:@"tecnicos"] objectAtIndex:indexPath.row];

        cellStaff.name.text = [staffDic valueForKey:@"nom"];

        cellStaff.role.text = [staffDic valueForKey:@"posicion"];

        return cellStaff;

    }

    return nil;
}

Xcode给我这个错误:Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<teamCell 0x8d4f6b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key role.'并且执行在行

处中断
teamCell *cellTeam = [table dequeueReusableCellWithIdentifier:@"equipo"]; 

感谢您的帮助。

非常感谢。

0 个答案:

没有答案