当我的UITableViewCell行显示出来时,它们的高度为44,绝对不应该这样做。我已经限制了整个路径的顶部到底部,正如您在下面的警告中看到的关于不良约束。
忽略它不喜欢我的$ ballIsSquare $高度/宽度约束的事实,我仍然应该有一个高度超过44的单元格。它显示几乎圆形的球,意味着高度几乎是55高(因为它显示$ ballWidth $为55.但是,它根本没有显示日期标签,这被限制在球的上方。任何想法细胞是什么被迫如此小?
视图控制器为此指定估计行高100,并且rowHeight设置为UITableViewAutomaticDimension。
我认为“UISV-alignment”和UISV-canvas-connection是来自正在使用的UIStackView的约束(例如$ ballsBottom $指的是球UIStackView)
UIView-Encapsulated-Layout-Height在我看来是真正的问题。
"<NSLayoutConstraint:0x60400008d070 '$ballIsSquare$' DidIWin.BallView:0x7f8525a3fec0.height == DidIWin.BallView:0x7f8525a3fec0.width (active)>",
"<NSLayoutConstraint:0x604000091ad0 '$ballsBottom$' DidIWin.Balls:0x7f8525a3e890.bottom == UILayoutGuide:0x6040001a6c80'UIViewSafeAreaLayoutGuide'.bottom - 10 (active)>",
"<NSLayoutConstraint:0x604000086c70 '$ballWidth$' DidIWin.BallView:0x7f8525a3fec0.width == 55 (active)>",
"<NSLayoutConstraint:0x6040000928e0 '$largeDateBottom$' UILabel:0x7f8525a44510'10/4/17'.bottom == DidIWin.Balls:0x7f8525a3e890.top + 10 (active)>",
"<NSLayoutConstraint:0x604000092840 '$largeDateTop$' UILabel:0x7f8525a44510'10/4/17'.top == UILayoutGuide:0x6040001a6c80'UIViewSafeAreaLayoutGuide'.top + 10 (active)>",
"<NSLayoutConstraint:0x604000092020 'UISV-alignment' DidIWin.BallView:0x7f8525a3ead0.bottom == DidIWin.BallView:0x7f8525a3fec0.bottom (active)>",
"<NSLayoutConstraint:0x604000091f30 'UISV-alignment' DidIWin.BallView:0x7f8525a3ead0.top == DidIWin.BallView:0x7f8525a3fec0.top (active)>",
"<NSLayoutConstraint:0x60400008c670 'UISV-canvas-connection' DidIWin.Balls:0x7f8525a3e890.top == DidIWin.BallView:0x7f8525a3ead0.top (active)>",
"<NSLayoutConstraint:0x604000091c60 'UISV-canvas-connection' V:[DidIWin.BallView:0x7f8525a3ead0]-(0)-| (active, names: '|':DidIWin.Balls:0x7f8525a3e890 )>",
"<NSLayoutConstraint:0x604000091da0 'UIView-Encapsulated-Layout-Height' DidIWin.FailureDetailCell:0x7f8526047200'failure'.height == 44 (active)>",
"<NSLayoutConstraint:0x604000091940 'UIViewSafeAreaLayoutGuide-bottom' V:[UILayoutGuide:0x6040001a6c80'UIViewSafeAreaLayoutGuide']-(0)-| (active, names: '|':DidIWin.FailureDetailCell:0x7f8526047200'failure' )>",
"<NSLayoutConstraint:0x6040000918a0 'UIViewSafeAreaLayoutGuide-top' V:|-(0)-[UILayoutGuide:0x6040001a6c80'UIViewSafeAreaLayoutGuide'] (active, names: '|':DidIWin.FailureDetailCell:0x7f8526047200'failure' )>"
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400008d070 '$ballIsSquare$' DidIWin.BallView:0x7f8525a3fec0.height == DidIWin.BallView:0x7f8525a3fec0.width (active)>
答案 0 :(得分:-1)
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
if(indexPath.section == 0){
return 50
}else{
return 120
}
}
在视图控制器中添加此委托方法
或者您可以使用
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
用于自动尺寸