如何动态调整静态UITableViewCell的大小? [英] How do I dynamically resize a static UITableViewCell?

查看:85
本文介绍了如何动态调整静态UITableViewCell的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

包含标签的静态表格单元的动态高度?

我正在使用带有静态内容的UITableView。视图控制器没有实现委托或数据源协议中的任何内容(因为部分和单元格都在故事板中定义),只需使用连接为IBOutlets的UILabel插入文本内容。

I am using a UITableView with static content. The view controller does not implement anything from the delegate or datasource protocols (because the sections and cells are all defined in the storyboard), just inserts the text content using the UILabels wired as IBOutlets.

但现在我想动态设置一个特定单元格的高度。我该怎么做?

But now I want to set the height of one particular cell dynamically. How can I do this?

推荐答案

如果你需要在运行时定义单元格的高度,你必须实现 UITableViewDelegate tableView:heightForRowAtIndexPath:方法。这有点痛苦,但这是你能够以编程方式计算单元格高度并在表格需要显示时将其返回到表格的唯一方法。

If you need to define the height of the cell at runtime, you must implement the tableView:heightForRowAtIndexPath: method of the UITableViewDelegate. It's a bit of a pain, but it's the only way you'll be able to programatically calculate the height of the cell and return it to the table when the table need to display it.

这篇关于如何动态调整静态UITableViewCell的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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