Tôi đang sử dụng đoạn mã sau để có UITableViewCell có một chiều cao năng động:Swift/làm thế nào để sử dụng UITextView với chiều cao năng động INSIDE UITableViewCell với chiều cao năng động
tableView.estimatedRowHeight = 155
tableView.rowHeight = UITableViewAutomaticDimension
Và đoạn mã này để có UITextView thay đổi đó là chiều cao dựa trên nội dung.
extension NewUserTweetTableVC: UITextViewDelegate {
func textViewDidChange(textView: UITextView) {
let fixedWidth = textView.frame.size.width
textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
var newFrame = textView.frame
newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)
textView.frame = newFrame
}
}
Khi tôi thay đổi văn bản của UITextView trong thời gian chạy, chiều cao của thay đổi UITextView, nhưng chiều cao của UITableViewCell thì không. Làm thế nào tôi có thể thay đổi điều đó? Trợ giúp rất được đánh giá cao.
Kiểm tra câu hỏi này: - http://stackoverflow.com/questions/37014919/expand-uitextview-and-uitableview-when-uitextviews-text-extends-beyond-1-line – Rahul