简体   繁体   English

运行时与情节提要XCode9中不同的单元格高度

[英]Different cell height at runtime than in storyboard XCode9

在此处输入图片说明

I've got a cell that I've made a subclass for and am setting up all the layout stuff in the storyboard. 我有一个要为其创建子类的单元,并且正在情节提要中设置所有布局内容。 On runtime, the cells are way shorter than I have them set to be in the storyboard. 在运行时,这些单元比我在情节提要中设置的单元短得多。

I'm getting a different background color and height in the simulator. 我在模拟器中得到了不同的背景颜色和高度。

class FeedCell: UITableViewCell {
@IBOutlet weak var profileImage: UIImageView!
@IBOutlet weak var emailLabel: UILabel!
@IBOutlet weak var messageLabel: UILabel!

func configureCell(profileImage : UIImage, email : String, content : String) {
    self.profileImage.image = profileImage
    self.emailLabel.text = email
    self.messageLabel.text = content
}
override func awakeFromNib() {
    super.awakeFromNib()
}
 }

That's the only code I've got in my subclass. 那是我子类中唯一的代码。

Any ideas? 有任何想法吗?

Set proper constraint to table cell and set table view dynamic height using estimatedRowHeight and rowHeight 为表单元格设置适当的约束,并使用estimatedRowHeightrowHeight设置表视图动态高度

eg 例如

    tableView.estimatedRowHeight = 120
    tableView.rowHeight = UITableViewAutomaticDimension

When you create self-sizing table view cell (dynamic row height), use proper constraints to define cell's size and set the below properties ( rowHeight , estimatedRowHeight ) inside viewDidLoad method. 当创建自上浆表视图细胞(动态行高度)时,使用正确的约束条件来定义单元格的大小,并设置以下属性( rowHeight,estimatedRowHeight)viewDidLoad方法。

override func viewDidLoad() {
    super.viewDidLoad()

    self.yourTableView.rowHeight = UITableViewAutomaticDimension
    self.yourTableView.estimatedRowHeight = 130
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM