Swift - 随 UITextView 一起增长的静态 UITableView
Swift - Static UITableView growing with UITextView
我有一个静态 UITableView,我的其中一行有一个 UITextView,自动布局从上到下从左到右固定为 0。
我希望 UITableView 的 contentView 根据 UITextView 的内容调整大小,但是我在解决这个问题时遇到了困难。我已经废弃了我最初使用的代码,因为它根本不起作用。有什么解决办法吗?
如果textview的内容是静态的。
在 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
}
如果textview的内容是动态的。
做与静态相同的事情,将 UITextView 的委托设置为 self。然后在 UITextview 委托中。
func textViewDidChange(_ textView: UITextView) {
tableView.beginUpdates()
tableView.endUpdates()
}
这绝对有效。
我有一个静态 UITableView,我的其中一行有一个 UITextView,自动布局从上到下从左到右固定为 0。
我希望 UITableView 的 contentView 根据 UITextView 的内容调整大小,但是我在解决这个问题时遇到了困难。我已经废弃了我最初使用的代码,因为它根本不起作用。有什么解决办法吗?
如果textview的内容是静态的。 在 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
}
如果textview的内容是动态的。
做与静态相同的事情,将 UITextView 的委托设置为 self。然后在 UITextview 委托中。
func textViewDidChange(_ textView: UITextView) {
tableView.beginUpdates()
tableView.endUpdates()
}
这绝对有效。