iOS如何在没有自动布局的情况下设置动态tableview单元格高度?
我使用带有三个标签标题、日期和描述的自定义tableview单元格,现在我从web服务获取数据,其中一些描述文本太大,无法在描述标签的框架内进行调整iOS如何在没有自动布局的情况下设置动态tableview单元格高度?,ios,objective-c,swift,tableview,Ios,Objective C,Swift,Tableview,我使用带有三个标签标题、日期和描述的自定义tableview单元格,现在我从web服务获取数据,其中一些描述文本太大,无法在描述标签的框架内进行调整 如何进行 写入viewDidLoad tableView.estimatedRowHeight = 50 tableView.rowHeight = UITableViewAutomaticDimension 简单地使用like 目标-C - (void)viewDidLoad { ... ... self.tableView.estimated
如何进行 写入
viewDidLoad
tableView.estimatedRowHeight = 50
tableView.rowHeight = UITableViewAutomaticDimension
简单地使用like
目标-C
- (void)viewDidLoad
{
...
...
self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80; // customize the height
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
Swift
override func viewDidLoad() {
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80 // customize the height
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
目标-C
- (void)viewDidLoad
{
...
...
self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80; // customize the height
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
Swift
override func viewDidLoad() {
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80 // customize the height
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
最后在属性或编程中设置your label.numofLines=0,我想知道为什么要寻找不使用自动布局的方法。我相信之前发布的答案是使用自动布局的解决方案 自动布局 您可以设置为根据标签的内容展开 没有自动布局
如果没有autolayout,您需要单独计算每个单元格的高度(+边距),并在UITableView数据源方法中返回值
-tableView:heightForRowAtIndexPath:
,谢谢,但问题尚未解决
请检查图片
self.tableView.rowHeight=UITableViewAutomaticDimension代码>
还有
heightforcellmethod一切都一团糟
我的带有故事板的桌面视图请检查“大小检查器”选项卡中的“自动调整大小”部分
我在这里做错了什么?请在下面的评论中检查我的问题请在下面的评论中检查我的问题您必须将标签行号设置为0,是否使用
self.tableView.estimateDroweight=当前行高
`