Ios 在对静态单元格使用UITableViewAutomaticDimension后,单元格高度太小

Ios 在对静态单元格使用UITableViewAutomaticDimension后,单元格高度太小,ios,swift,uitableview,autolayout,Ios,Swift,Uitableview,Autolayout,在对静态单元格使用UITableViewAutomaticDimension后(这些单元格是“右细节单元格”,因此我无法对单元格的高度设置任何约束) 细胞的高度变得越来越小。有没有办法解决这个问题( 提前谢谢 代码: override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return UITableViewAutomaticDimen

在对静态单元格使用
UITableViewAutomaticDimension
后(这些单元格是“右细节单元格”,因此我无法对单元格的高度设置任何约束)

细胞的高度变得越来越小。有没有办法解决这个问题(

提前谢谢

代码:

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 65
}

override func viewWillAppear(_ animated: Bool) {
    tableView.estimatedRowHeight = 65
    tableView.rowHeight = UITableViewAutomaticDimension
}
编辑:

使用
UITableViewAutomaticDimension
时,似乎没有
约束就无法扩展高度,因此我手动设置
行高

struct DeviceSize {
    static let iPhoneSE = (width:Float(320.0), height:Float(568.0))
    static let iPhone7 = (width: Float(375.0), height:Float(667.0))
    static let iPhone7P = (width: Float(414.0), height:Float(736.0))
}

override func tableView(_ tableView: UITableView,
               heightForRowAt indexPath: IndexPath) -> CGFloat {
    let height = Float(UIScreen.main.bounds.size.height)
    switch height {
    case DeviceSize.iPhoneSE.height:
        return 55
    case DeviceSize.iPhone7.height:
        return 60
    case DeviceSize.iPhone7P.height:
        return 65
    default:
        return 65
    }
}

在单元格内,将高度约束大于或等于的标签设置为所需的最小高度。
自动标注尺寸
使单元格高度取决于标签的文本内容。只需给标签一个最小高度,如在单元格内,设置高度约束大于或等于的标签
设置为所需的最小高度。
自动尺寸标注
根据标签的文本内容设置单元格高度。如果使用自动尺寸标注,只需为标签设置一个最小高度,如

,则会自动计算单元格高度。手动设置行高度

这些线路不是必需的

override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 65
}
override func viewWillAppear(_ animated: Bool) {
    tableView.estimatedRowHeight = 65
   tableView.rowHeight = UITableViewAutomaticDimension
}
解决方案:

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    if indexPath.row == 0{
    //.... return height whatever you want for indexPath.row
    return 40
    }else {
    return 30
    }
}

如果使用自动标注,则将自动计算单元格高度。请手动设置行高度

这些线路不是必需的

override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 65
}
override func viewWillAppear(_ animated: Bool) {
    tableView.estimatedRowHeight = 65
   tableView.rowHeight = UITableViewAutomaticDimension
}
解决方案:

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    if indexPath.row == 0{
    //.... return height whatever you want for indexPath.row
    return 40
    }else {
    return 30
    }
}

tableView.estimatedRowHeight=UITableViewAutomaticDimensionTableView.rowHeight=UITableViewAutomaticDimensionOverride func tableView(uTableView:UITableView,estimatedHeightForRowAt indexPath:IndexXPath)->CGFloat{return UITableViewAutomaticDimensions}放置一个断点并检查,是否调用了方法。@VibhaSingh我刚刚尝试了您的代码,但它似乎不起作用。@VigneshDavins我已经检查了,并且调用了方法。tableView.estimatedRowHeight=UITableViewAutomaticDimension tableView.rowHeight=UITableViewAutomaticDimension override func tableView(uTableView:UITableView,估计权重为indexPath:indexPath)->CGFloat{return UITableViewAutomaticDimension}放置一个断点并检查,方法是否被调用。@VibhaSingh我刚刚尝试了你的代码,似乎它不起作用。@VigneshDavins我已经检查了,方法被调用了。谢谢,但就像我说的,我不能在正确的详细信息单元格内设置标题标签的约束。我想这个解决方案可以在自定义单元格上工作。谢谢,但是就像我说的,我不能为右细节单元格内的标题标签设置约束。我认为这个解决方案适用于自定义单元格。基本上,我尝试使用UITableViewAutomaticDimension的原因是调整iPhone SE的单元格高度(iPhone SE上的单元格太大,但在iPhone 6、7等上看起来不错)。很遗憾,为每一行设置常量值是行不通的。我可以从UIScreen获取屏幕比率并手动设置单元格高度,但我认为这有点混乱,所以我想知道是否有UITableViewAutomaticDimension的解决方案。基本上,我尝试使用UITableViewAutomaticDimension的原因是调整我的单元格高度Phone SE(手机在iPhone SE上太大了,但在iPhone 6、7等等上看起来很不错)。所以不幸的是,为每行设置常量值不起作用。我可以从UIScreen获取屏幕比率并手动设置手机高度,但我认为这有点混乱,所以我想知道是否有UITableViewAutomaticDimension的解决方案