Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewAutomaticDimension未调整为UILabel文本高度_Ios_Swift_Uitableview - Fatal编程技术网

Ios UITableViewAutomaticDimension未调整为UILabel文本高度

Ios UITableViewAutomaticDimension未调整为UILabel文本高度,ios,swift,uitableview,Ios,Swift,Uitableview,我有一个消息传递应用程序,并在气泡视图的每一侧将标签约束设置为8。我没有设置高度限制,正在试图弄清楚为什么滚动时标签在某些单元格上随机显示更多的高度和错误的大小: tableView.rowHeight = UITableViewAutomaticDimension tableView.estimatedRowHeight = 30 标签设置为行数0,也设置为换行 func configureCell(message: MessageCD) { self.me

我有一个消息传递应用程序,并在气泡视图的每一侧将标签约束设置为8。我没有设置高度限制,正在试图弄清楚为什么滚动时标签在某些单元格上随机显示更多的高度和错误的大小:

    tableView.rowHeight = UITableViewAutomaticDimension
    tableView.estimatedRowHeight = 30
标签设置为行数0,也设置为换行

    func configureCell(message: MessageCD) {

    self.message = message

    let username = message.getSender()?.username
    let text = message.text

    if username == UserDefaults.standard.value(forKey: USERNAME) as? String {

        senderLbl.text = text
        recipientBubbleView.isHidden = true
        senderBubbleView.isHidden = false
    } else {
        recipientLbl.text = text
        senderBubbleView.isHidden = true
        recipientBubbleView.isHidden = false
    }
}

我还尝试在设置标签后立即使用sizeToFit(),但这也不起作用。请参阅附图。

内容优先权解决了此问题

if msgUsername == UserDefaults.standard.value(forKey: USERNAME) as? String {

        recipientLbl.setContentHuggingPriority(250, for: UILayoutConstraintAxis.vertical)
        senderLbl.setContentHuggingPriority(750, for: UILayoutConstraintAxis.vertical)
        senderLbl.text = message.text
        senderLbl.sizeToFit()
        recipientUsernameLbl.isHidden = true
        recipientBubbleView.isHidden = true
        senderBubbleView.isHidden = false

    } else {

        senderLbl.setContentHuggingPriority(250, for: UILayoutConstraintAxis.vertical)
        recipientLbl.setContentHuggingPriority(750, for: UILayoutConstraintAxis.vertical)
        recipientLbl.text = message.text
        recipientUsernameLbl.text = msgUsername
        recipientUsernameLbl.isHidden = false
        recipientLbl.sizeToFit()
        senderBubbleView.isHidden = true
        recipientBubbleView.isHidden = false
    }

内容优先解决了这个问题

if msgUsername == UserDefaults.standard.value(forKey: USERNAME) as? String {

        recipientLbl.setContentHuggingPriority(250, for: UILayoutConstraintAxis.vertical)
        senderLbl.setContentHuggingPriority(750, for: UILayoutConstraintAxis.vertical)
        senderLbl.text = message.text
        senderLbl.sizeToFit()
        recipientUsernameLbl.isHidden = true
        recipientBubbleView.isHidden = true
        senderBubbleView.isHidden = false

    } else {

        senderLbl.setContentHuggingPriority(250, for: UILayoutConstraintAxis.vertical)
        recipientLbl.setContentHuggingPriority(750, for: UILayoutConstraintAxis.vertical)
        recipientLbl.text = message.text
        recipientUsernameLbl.text = msgUsername
        recipientUsernameLbl.isHidden = false
        recipientLbl.sizeToFit()
        senderBubbleView.isHidden = true
        recipientBubbleView.isHidden = false
    }

Xcode 8或Xcode 9?还有bubbleview上的约束是什么?Xcode 8和bubble视图上的约束固定在8边上,从边缘开始的前导和尾随>=100,具体取决于其位于左侧还是右侧。bubbleview没有高度或其他任何东西,也没有顶部和底部8?上一次尝试是因为我在移动设备上,但将标签上的抗压缩和内容拥抱设置为一个非常高的数字,并给出goXcode 8或Xcode 9?bubbleview上的约束是什么?Xcode 8和bubble视图上的约束固定在侧面8,根据其位于左侧还是右侧,前缘和后缘距离边缘>=100。bubbleview没有高度或其他任何东西,顶部和底部也有8?我在手机上最后一次尝试,但将标签上的抗压缩和内容拥抱设置为一个非常高的数字,并尝试一下