Ios 自调整表视图单元格大小是';行不通

Ios 自调整表视图单元格大小是';行不通,ios,swift,uitableview,Ios,Swift,Uitableview,我将estimatedRowHeight设置为常量,并将rowHeight设置为UITableViewAutomaticDimension,但表格视图单元格的大小仍未调整为单元格的detailTextLabel。我哪里做错了 override func viewDidLoad() { super.viewDidLoad() tableView.estimatedRowHeight = 130.0 tableView.tableFooterView = UIView()

我将
estimatedRowHeight
设置为常量,并将
rowHeight
设置为
UITableViewAutomaticDimension
,但表格视图单元格的大小仍未调整为单元格的detailTextLabel。我哪里做错了

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.estimatedRowHeight = 130.0
    tableView.tableFooterView = UIView()
    tableView.separatorInset.left = 50
    tableView.registerClass(CommentCellView.self, forCellReuseIdentifier: cellid)
    tableView.rowHeight = UITableViewAutomaticDimension


}

override func viewDidAppear(animated: Bool) {
    tableView.reloadData()
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier(cellid, forIndexPath: indexPath) as! CommentCellView

    return cell
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 5

}

override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 60.0
}
UITableViewCell类:

class CommentCellView: UITableViewCell {
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: .Subtitle, reuseIdentifier: reuseIdentifier)

        detailTextLabel?.numberOfLines = 0
        detailTextLabel?.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

}

设置标签(本例中称为
yourText

以这种方式设置单元格约束,并将
setupComponents
方法放在此处:

 required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        setupComponents()
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: .Subtitle, reuseIdentifier: "CellId")

        setupComponents()

    }

        func setupComponents(){



    self.addSubview(yourText)

    yourText.leftAnchor.constraintEqualToAnchor(self.leftAnchor, constant: 6).active = true
            yourText.centerYAnchor.constraintEqualToAnchor(self.centerYAnchor).active = true
            yourText.widthAnchor.constraintEqualToConstant(110).active = true

    yourText.numberOfLines = 0

    yourText.lineBreakMode = NSLineBreakMode.ByWordWrapping
     self.bottomAnchor.constraintEqualToAnchor(yourText.bottomAnchor, constant: 5).active = true
    }

表视图单元格中是否有适当的自动布局约束?请尝试删除您的
EstimatedHeightForrowtIndexPath
func
 required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        setupComponents()
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: .Subtitle, reuseIdentifier: "CellId")

        setupComponents()

    }

        func setupComponents(){



    self.addSubview(yourText)

    yourText.leftAnchor.constraintEqualToAnchor(self.leftAnchor, constant: 6).active = true
            yourText.centerYAnchor.constraintEqualToAnchor(self.centerYAnchor).active = true
            yourText.widthAnchor.constraintEqualToConstant(110).active = true

    yourText.numberOfLines = 0

    yourText.lineBreakMode = NSLineBreakMode.ByWordWrapping
     self.bottomAnchor.constraintEqualToAnchor(yourText.bottomAnchor, constant: 5).active = true
    }