ios - 调整大小的UITableViewCell : toggling UITextView in UITableViewCell by using auto layouts

标签 ios swift uitableview autolayout

这是我创建的。

enter image description here

请忽略模糊部分,这是创建 .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
    }

}

其中hctextview的高度约束。我的疑问是,切换下面的 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/

相关文章:

ios - 如何在声明函数之外访问单元格属性?

ios - 在 ViewController 中设置了 TableView 的数据源和委托(delegate),但没有任何反应

ios - 我们是否需要为 CocoaPods 和 Carthage 创建 iOS 通用框架?

iOS 滑动效果 ViewControllers - Instagram 事件选项卡

ios - NSArchiver 与 NSKeyedArchiver

iOS 11 - 使用大标题作为导航 (Swift)

swift - Metal:一旦为 MSL cikernel 设置编译器和链接器选项,.metal 文件中定义的 vertexFunction 将变为 nil

swift - 检查输入是否快速 float

ios - UIViewController 没有成员 'method'

ios - AFNetworking 处理来自 php 脚本的响应