从自定义单元格加载时如何调整单元格表的高度? [英] How to adjust the height of the cell table when loading from the custom cells?

查看:106
本文介绍了从自定义单元格加载时如何调整单元格表的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我从3种类型的自定义单元格中加载 UITableView 。我为此制作了3个自定义类,并使用布局子视图方法添加了所有元素Programmatic。但问题是所有3都有文本视图。它可以变化。在该文本视图内容之后,我需要添加一个按钮和一个标签。我可以做,但如何根据内容视图大小增加单元格的大小?

I have an application in which I am loading a UITableView from 3 types custom cells. I made 3 custom classes for that and added all the elements Programmatic by using layout subview method. But the issue is all the 3 has a text view in it. it can be variable. after that text view content I need to add a button and a label. That I can do, but how to increase the size of the cell according to the content view size?

推荐答案

请检查自定义单元格高度将与每个单元格高度的表格视图相同。

Please check the custom cell height will be the same as table view each cell height.

您可以使用以下功能调整表视图的单元格高度。

You can use following function to adjust table view's cell height.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return height;
}

您可以使用这样的代码。

You can use code like this.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Defination *definition = [self.dataSource objectAtIndex:indexPath.row];
    NSString *detailString = definition.detailString;
    CGSize detailSize;
    detailSize = [detailString sizeWithFont:fontSize(12.0) constrainedToSize:CGSizeMake(420, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];

    return detailSize.height + 20.0;
}

这篇关于从自定义单元格加载时如何调整单元格表的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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