在同一个表视图上使用两个不同的单元标识符 [英] Use two different cell identifier on same table view

查看:72
本文介绍了在同一个表视图上使用两个不同的单元标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图摆脱一个缓存的UITableView单元格。我有两个部分。第二部分的第一单元具有与第一部分的第一单元相同的外观。外观我的意思是单元格的高度(多行单元格)。

I'm trying to get rid of a cached UITableView cell. I have two sections. The first cell of the second section has the same "appearance" as the first cell of the first section. With appearance I mean the cell height (multiline cells).

我试图使用不同的标识符,但是没有工作。下面是代码:

I tried to use different identifiers, but that didn't worked. Here is the code:

NSString *identifier;
if (thisViewMode) {
    identifier = @"thisViewMode";
} else if ((indexPath.section == 1) && thatViewMode) {
    identifier = @"thatViewMode";
} else {
    identifier = @"CellIdentifier";
}

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
    cell = [self CreateMultilinesCell:identifier];
}

thatViewMode 调用一次,这是不对的,因为我有更多的细胞在我的第二部分。如果我改变第一部分中的第一单元的内容,则第二部分中的第一单元的高度也改变。通常每个单元格应该有自己的单元格高度,但这不是这里的情况。

thatViewMode is only called once, which isn't right because I have more cells in my second section. If I change the content of the first cell in the first section, the height of the first cell in the second section also changes too. Normally each cell should have it's own cell height, but that isn't the case here.

有一个问题,我不能使用不同的单元格标识符表格视图?

Is there a problem that I can't use different cell identifiers on the same table view?

推荐答案

我忘记也适应 heightForRowAtIndexPath

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
        // do something
    } else {
        // do something different
    }
    return ...
}

这篇关于在同一个表视图上使用两个不同的单元标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆