UITableViewAutomaticDimension与Subtitle UITableViewCells无法正常工作

gpb*_*pbl 6 uitableview uikit ios ios8

我正在创建2个部分UITableView.第一部分使用UITableViewCellsDefault风格,第二个使用Subtitle风格.两个单元格都可以具有多行文本标签.

我把桌子设置rowHeightUITableViewAutomaticDimension.

正如您从下面的屏幕截图中看到的那样,UITableViewAutomaticDimension在使用Subtitle样式时仅部分尊重:高度似乎适合textLabel高度但不适合高度detailLabel.

如何让Subtitle细胞达到合适的高度?

一些代码:

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.estimatedRowHeight = 80
    tableView.rowHeight = UITableViewAutomaticDimension

    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "defaultCell")
    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "subtitleCell")
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    if indexPath.section === 1 {
        var cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "subtitleCell")
        cell.textLabel?.numberOfLines = 0
        cell.textLabel?.text = "A Long text..."
        cell.detailTextLabel?.numberOfLines = 0
        cell.detailTextLabel?.text =  "A Long text..."
        return cell
    }
    else {
        var cell = tableView.dequeueReusableCellWithIdentifier("defaultCell") as! UITableViewCell

        cell.textLabel!.text = "A long text..."
        cell.textLabel?.numberOfLines = 0
        return cell
    }

}
Run Code Online (Sandbox Code Playgroud)

我试图实现一个子类,UITableViewCell但是我遇到了autolayout和section titles(很长的故事)的许多问题,所以我想知道我是否能以更简单的方式解决问题.

Wil*_* Hu 0

刚刚试了一下Xcode 9iPhone 8 simulator效果非常好。

代码在这里https://github.com/williamhqs/testSubtitleCellLayout

在此输入图像描述