我有一个静态 UITableView
,它有 12 行,对于 11 行,我知道高度需要是多少。
我有一个 UILabel,它具有位于第 12 行内的动态文本,我如何着手让一个单元格具有基于 UILabel 中的文本的动态高度。
我已经在 viewDidLoad
中尝试了下面的代码,但没有成功。行保持相同的高度。我还为 UILabel
tableView.estimatedRowHeight = 100.0
tableView.rowHeight = UITableViewAutomaticDimension
最佳答案
你试过吗?
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if (indexPath.row < 11) {
// Everything starts at 0, so this covers 0-10
// Whatever your cell height is
return <#fixedCellHeight#>
} else {
// This is your 12th cell (indexPath.row 11), as we start counting at 0
return UITableViewAutomaticDimension
}
}
关于ios - 静态 UITableView,在 Swift 中创建具有动态高度的单个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32969347/