UITableView layout messing up on push segue and return. (iOS 8, Xcode beta 5, Swift)

后端 未结 7 904
清歌不尽
清歌不尽 2020-12-07 13:44

tldr; Auto constrains appear to break on push segue and return to view for custom cells

Edit: I have provided a github example proj

7条回答
  •  一个人的身影
    2020-12-07 14:23

    Well, until it works, you can delete those two line:

    self.tableView.estimatedRowHeight = 45
    self.tableView.rowHeight = UITableViewAutomaticDimension
    

    And add this method to your viewController:

    override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell") as TableViewCell
        cell.cellLabel.text = self.tableArray[indexPath.row]
    
        //Leading space to container margin constraint: 0, Trailling space to container margin constraint: 0
        let width = tableView.frame.size.width - 0
        let size = cell.cellLabel.sizeThatFits(CGSizeMake(width, CGFloat(FLT_MAX)))
    
        //Top space to container margin constraint: 0, Bottom space to container margin constraint: 0, cell line: 1
        let height = size.height + 1
    
        return (height <= 45) ? 45 : height
    }
    

    It worked without any other changes in your test project.

提交回复
热议问题