如何根据内容设置单元格的动态高度 [英] How to set dynamic height of cell based on content

查看:139
本文介绍了如何根据内容设置单元格的动态高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,需要在表格单元格中显示用户注释。如何根据Instagram中的单元格内容设置单元格的动态高度?

I am have an app which requires to display user comments within a table cell. How can I set the dynamic height of the cell based on the contents of the cell like in Instagram?

基本上,我的文本和注释在不同的单元格中具有不同的长度。任何人都可以告诉我如何实现动态高度方法(如instagram)?

Basically, I have texts and comments that have different length in different cells. Can anyone advise me on how I can implement the dynamic height method (like instagram)?

推荐答案

检查 UITableViewDelegate文档

- (CGFloat)tableView:(UITableView *)tableView 
                                heightForRowAtIndexPath:(NSIndexPath *)indexPath

请记住,您无法从此方法引用单元格,因此您需要分别计算内容的高度并用它来产生高度。

Bear in mind you can't reference the cell from this method, so you want to calculate the height of the contents separately and use it to generate the height.

这篇关于如何根据内容设置单元格的动态高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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