根据其内容自动调整UITableViewCell高度 [英] Auto adjust the UITableViewCell height depending on its contents

查看:84
本文介绍了根据其内容自动调整UITableViewCell高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据内容调整单元格的高度。我知道UITableViewDelegate允许你实现

I want to adjust the height of a cell depending on its contents. I know UITableViewDelegate lets you implement the

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

但我不想硬编码高度。有没有办法动态地执行此操作?

but I do not want to hardcode the height. Is there a way to do this dynamically?

推荐答案

您必须在该方法中输入一些代码来计算行的高度内容。确切地说,您需要放置的代码完全取决于您正在显示的内容类型。

You have to enter some code into that method that calculates the height of the row content. Exactly what code you need to put depends entirely on what kind of content you're displaying.

例如,如果您要显示可能包含多行的文本内容,您可能最终会使用NSString的之一sizeWithFont:方法族。

For example, if you're displaying text content that may wrap across multiple lines, you're probably going to end up using one of NSString's sizeWithFont: family of methods.

这篇关于根据其内容自动调整UITableViewCell高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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