ios - UITableViewAutomaticDimension 导致内容 View 高度错误

标签 ios swift uitableview

我有几个自定义单元格(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 的屏幕截图。

enter image description here

我怎样才能做到这一点?提前致谢。

最佳答案

在您的 View 层次结构中,您的 Container 不是必需的。您应该删除它并将所有 subview 直接放在 Content View 中。

关于ios - UITableViewAutomaticDimension 导致内容 View 高度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33395249/

相关文章:

ios - 如何在继续之前等待功能完成

ios - Swift UILabel subview 不更新

ios - 从单元格创建事件 (IBAction)

ios - UISearchDisplayController 表格框架

ios - 返回数组的函数没有在 for 循环 Swift 中获取附加内容

ios - 放大到 map 上的当前位置

iPhone:如何在drawRect中换行文本?

ios - uitableViewCell 的索引路径

ios - UIButton 的一部分不响应触摸事件

iphone - 应用内购买适用于 iOS 3 和 5,但不适用于 iOS 4