Ios Swift-静态UITableView随UITextView增长

Ios Swift-静态UITableView随UITextView增长,ios,swift,uitableview,uitextview,Ios,Swift,Uitableview,Uitextview,我有一个静态UITableView,其中一行有一个UITextView,其中autolayout从上到下从左到右固定为0 我希望UITableView的contentView根据UITextView的内容调整大小,但是我在解决这个问题时遇到了困难。我已经废弃了我最初使用的代码,因为它根本不起作用。有什么解决方案吗?如果文本视图的内容是静态的。 在UITextView中将SrollingEnabled设置为false func tableView(_ tableView: UITableView,

我有一个静态UITableView,其中一行有一个UITextView,其中autolayout从上到下从左到右固定为0


我希望UITableView的contentView根据UITextView的内容调整大小,但是我在解决这个问题时遇到了困难。我已经废弃了我最初使用的代码,因为它根本不起作用。有什么解决方案吗?

如果文本视图的内容是静态的。 在UITextView中将SrollingEnabled设置为false

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 200
}

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

如果文本视图的内容是动态的。

执行与static相同的操作,并将UITextView的委托设置为self。然后在UITextview中委派

   func textViewDidChange(_ textView: UITextView) {
    tableView.beginUpdates()
    tableView.endUpdates()
}

如果文本视图的内容是静态的,这肯定会起作用。

在UITextView中将SrollingEnabled设置为false

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 200
}

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

如果文本视图的内容是动态的。

执行与static相同的操作,并将UITextView的委托设置为self。然后在UITextview中委派

   func textViewDidChange(_ textView: UITextView) {
    tableView.beginUpdates()
    tableView.endUpdates()
}

这肯定会奏效。

太好了。唯一的问题是,它不会在我键入时自动更新,UITextView的内容不是静态的和变化的。请告诉我你是否得到了它。哈哈,在你编辑你的答案之前,我确实做到了,但它是正确的。谢谢。很好,这很有效。唯一的问题是,它不会在我键入时自动更新,UITextView的内容不是静态的和变化的。如果你没有得到它,请告诉我。哈哈,在你编辑你的答案之前,我确实做到了,但它是正确的,谢谢。