【发布时间】:2016-06-10 14:30:23
【问题描述】:
我有一个自定义表格视图单元格,我想根据标签中的文本量自动调整其大小。
在我的表格视图控制器中,我使用 UITableViewAutomaticDimension
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.section == 0 {
if indexPath.row == 0 {
return 200
} else {
return 49
}
} else if indexPath.section == 1 {
return 100
} else if indexPath.section == 2 {
if indexPath.row == 0 {
return 200
} else {
return 400
}
} else {
return UITableViewAutomaticDimension
}
}
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
这就是我最终的结果。
【问题讨论】:
-
确保将 contentView 的尾部、前导、顶部和底部连接到它的子视图。
-
你看过这篇文章了吗? stackoverflow.com/questions/18746929/…
-
做link this之类的,对你有帮助
标签: ios swift uitableview