我有几个自定义单元格(UITableViewCell
的子类)。显然,当我使用 UITableViewAutomaticDimension
时,内容 View 的高度不会更改为实际的单元格高度。我已经阅读了一些 QA,但似乎没有一个能解决我的问题。
viewDidLoad:
现在一切正常,单元格根据 UITextView 内容获得不同的高度。
override func viewDidLoad() {
super.viewDidLoad()
//Row Initial Settings
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 260
//Register Cell
self.tableView.registerNib(UINib(nibName: "CustomTableViewCell", bundle: nil), forCellReuseIdentifier: "CustomCell")
}
现在我希望我的自定义单元格 Content View 也匹配单元格的高度。
heightForRowAtIndexPath:
我知道我的 subview 约束是正确的,因为如果我使用 heightForRowAtIndexPath:
一切都完美契合,但我不想要 1 个单元格高度,每个单元格都有不同的设置。
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
//Fixed Cell Hight
return 200
}
历史 View 的屏幕截图。
我怎样才能做到这一点?提前致谢。
最佳答案
在您的 View 层次结构中,您的 Container
不是必需的。您应该删除它并将所有 subview 直接放在 Content View
中。
关于ios - UITableViewAutomaticDimension 导致内容 View 高度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33395249/