我在tableview中的不同部分使用自定义单元格。我知道我可以在Interface Builder中调整表格的高度。 但如果我有3个不同行高的部分,我如何控制tableview行的高度呢?
非常感谢
答案 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;
}