Swift UIView表视图中封装的布局高度约束问题 类ViewController:UITableViewController{ 重写func viewDidLoad(){ super.viewDidLoad() // https://stackoverflow.com/a/27148268/14016301 tableView.estimatedRowHeight=2.0 tableView.rowHeight=UITableView.automaticDimension } 重写func numberOfSections(在tableView:UITableView中)->Int{ 返回1 } 重写func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{ 返回1 } 重写func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{ let cell=UITableViewCell(样式:。默认值,reuseIdentifier:nil) cell.textlab?.text=“AAAA” 设h=cell.contentView.heightAnchor.constraint(equalToConstant:30) h、 isActive=true _=Timer.scheduledTimer(时间间隔为2,重复次数为false,块:{uuu}in UIView.animate(持续时间:0.5){ h、 常数=500 cell.layoutifneed()//此处存在布局问题 } }) 返回单元 } }

Swift UIView表视图中封装的布局高度约束问题 类ViewController:UITableViewController{ 重写func viewDidLoad(){ super.viewDidLoad() // https://stackoverflow.com/a/27148268/14016301 tableView.estimatedRowHeight=2.0 tableView.rowHeight=UITableView.automaticDimension } 重写func numberOfSections(在tableView:UITableView中)->Int{ 返回1 } 重写func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{ 返回1 } 重写func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{ let cell=UITableViewCell(样式:。默认值,reuseIdentifier:nil) cell.textlab?.text=“AAAA” 设h=cell.contentView.heightAnchor.constraint(equalToConstant:30) h、 isActive=true _=Timer.scheduledTimer(时间间隔为2,重复次数为false,块:{uuu}in UIView.animate(持续时间:0.5){ h、 常数=500 cell.layoutifneed()//此处存在布局问题 } }) 返回单元 } },swift,uitableview,uikit,tableview,uitableviewautomaticdimension,Swift,Uitableview,Uikit,Tableview,Uitableviewautomaticdimension,我想知道为什么这段代码会产生布局问题: 2021-02-18 20:59:18.679060+0200 nvrGonnaGivYouApp[23688:813946] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try t

我想知道为什么这段代码会产生布局问题:

2021-02-18 20:59:18.679060+0200 nvrGonnaGivYouApp[23688:813946] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600003c79400 UITableViewCellContentView:0x7fae0520c060.height == 500   (active)>",
    "<NSLayoutConstraint:0x600003c78f50 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fae0520c060.height == 30.3333   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600003c79400 UITableViewCellContentView:0x7fae0520c060.height == 500   (active)>
2021-02-18 20:59:18.679060+0200 nvrGonnaGivYouApp[23688:813946][LayoutConstraints]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(
"",
""
)
将尝试通过打破约束进行恢复
我试着寻找解决方案。但是它没有帮助(正如您可以看到的,我从中添加了解决方案)

我想要实现的是一个100%自动高度单元


谢谢

我不知道为什么会发生这个问题,但是

tableView.beginUpdate()
tableView.endUpdates()
不知怎么把它修好了

完整代码

类ViewController:UITableViewController{
重写func viewDidLoad(){
super.viewDidLoad()
// https://stackoverflow.com/a/27148268/14016301
tableView.estimatedRowHeight=2.0
tableView.rowHeight=UITableView.automaticDimension
}
重写func numberOfSections(在tableView:UITableView中)->Int{
返回1
}
重写func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
返回1
}
重写func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
let cell=UITableViewCell(样式:。默认值,reuseIdentifier:nil)
cell.textlab?.text=“AAAA”
设h=cell.contentView.heightAnchor.constraint(equalToConstant:30)
h、 优先级=.defaultHigh
h、 isActive=true
_=Timer.scheduledTimer(时间间隔为2,重复次数为false,块:{uuu}in
h、 常数=500
self.tableView.beginUpdate()
self.tableView.endUpdates()
})
返回单元
}
}