这是我创建的。
请忽略模糊部分,这是创建 .gif 时出现的问题。
我使用自动布局做到了这一点。
我的代码是:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.estimatedRowHeight = 100
self.tableView.rowHeight = UITableViewAutomaticDimension
}
对于用自定义单元格类编写的备注按钮的切换操作:
@IBAction func toggleAction(_ sender: Any) {
if(hc.constant == 75){
hc.constant = 0
}
else{
hc.constant = 75
}
}
其中hc是textview的高度约束。我的疑问是,切换下面的 TextView 后,tableviewcell 可以重新调整大小吗? 如果是,如何?
欢迎所有建议。谢谢。
最佳答案
更改常量后,如果在返回单元格之前更改,则必须调用 cell.contentView.layoutIfNeeded()
或 tableView.beginUpdate()
跟进 tableView .endUpdate()
更新表格 View 高度
您已经使用了UITableViewAutomaticDimension
,因此它应该根据约束自动更新
关于ios - 调整大小的UITableViewCell : toggling UITextView in UITableViewCell by using auto layouts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42218276/