在tableViewController中使用2个单元格标识符的奇怪行为

时间:2014-04-13 17:58:51

标签: ios objective-c uitableview

我正在使用TableviewController中的单元格标识符,我正在使用带有动态单元格的storyBoard。

我设置了2个带有2个标识符的单元格并使用了自定义行高:

enter image description here

在我的viewDidLoad中,我只是将一些检查信息插入mutableArray:

- (void)viewDidLoad
{
    [super viewDidLoad];

    _arrayCellContent = [[NSMutableArray alloc]init];
    for (int i=0; i<15; i++) {
        if (i%2 == 0) {
            [_arrayCellContent addObject:@"white"];
        }
        else
            [_arrayCellContent addObject:@"Brown"];
    }
}

我的cellForRow委托方法是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* identifierCellSlim = @"cellSlim";
    static NSString* identifierCellFat = @"cellFat";
    UITableViewCell *cellSlim = [tableView dequeueReusableCellWithIdentifier:identifierCellSlim forIndexPath:indexPath];
    UITableViewCell *cellFat = [tableView dequeueReusableCellWithIdentifier:identifierCellFat forIndexPath:indexPath];

    if (indexPath.row%2 ==0) {
        cellSlim.textLabel.text = self.arrayCellContent[indexPath.row];
        return cellSlim;
    }
    // Configure the cell...
    else {
        cellFat.textLabel.text = self.arrayCellContent[indexPath.row];
        cellFat.detailTextLabel.text = @"yalla";
        return cellFat;
    }
}

最终结果是: 甚至细胞排高度,没有打扮。这是为什么? (我知道我可以使用正确的委托方法解决这个问题,但我只是想知道IB为什么不做他的工作)

同样在开始时,单元格看起来是正确的颜色,但当我点击其中一些时,它们将转换为另一个单元格,

单击单元格会更改indexPath吗?  例如:

enter image description here

1 个答案:

答案 0 :(得分:0)

您正在同一方法调用中将两个单元格出列。

您应该检查给定NSIndexPath所需的单元格并使相关单元格出列。

相关问题