同一xib文件中的多个自定义单元格

时间:2019-05-04 13:32:42

标签: objective-c uitableview

我正在尝试从提供不同标识符的同一个xib加载多个自定义单元格。但这让我出错

  

为标识符(cell1)注册的笔尖无效-笔尖必须包含   一个顶层对象,它必须是UITableViewCell实例

这是我要在cellForRowAtIndexPath方法中尝试做的事情

MessageCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
    if(indexPath.row == 0){
    MessageCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
            if(!cell) {
                [tableView registerNib :[UINib nibWithNibName:@"MessageCustomCell" bundle:nil] forCellReuseIdentifier:@"cell1"];
                cell.msgLbl.text = [myArray objectAtIndex:indexPath.row];
        return cell;
    }
    }
    else {
        MessageCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
        if(!cell) {
            [tableView registerNib :[UINib nibWithNibName:@"MessageCustomCell" bundle:nil] forCellReuseIdentifier:@"cell1"];
            return cell;
    }
    }

从MessageCustomCell中删除第二个单元格后,代码运行正常。

0 个答案:

没有答案
相关问题