UITableView具有不同部分的不同行高

时间:2011-04-02 12:40:01

标签: iphone uitableview

我在tableview中的不同部分使用自定义单元格。我知道我可以在Interface Builder中调整表格的高度。 但如果我有3个不同行高的部分,我如何控制tableview行的高度呢?

非常感谢

2 个答案:

答案 0 :(得分:16)

UITableViewDelegate(最有可能是您的桌面视图的控制器)中实施tableView:heightForRowAtIndexPath:

答案 1 :(得分:3)

heightForRowAtIndexPath方法中设置包含此indexPath.section的部分。它设置了要为特定单元格设置不同行高的区段索引,然后设置其他区域。在其中设置indexPath.row它设置实际设置不同高度的行索引。

在下面的示例中,我为第4部分的第1个单元格设置了80.0f高度。其他人设为50.0f

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 3)
    {
        if (indexPath.row == 0)
        {
            return 80;
        }
    }
    else
    {
        return 50;
    }
    return 0;
}