在我的應用程序中,我有一個UITableView,其單元格包含具有不同內容的文本和UIButton。展開tableViewCell Swift
當用戶單擊單元格按鈕時,單元格應展開以顯示所有單元格的文本內容。所以展開的單元格的高度將因文本內容而異。
我搜索了很多關於這個問題,但沒有有用的結果:S。
我試過這種方法,但它並沒有給我正確的內容,有時細胞膨脹直,有時沒有,
let fixedWidth = tmpCell.textView.frame.size.width
tmpCell.textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))//CGFloat.max
let newSize = tmpCell.textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
var newFrame = tmpCell.textView.frame
newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)
tmpCell.textView.frame = newFrame
self.heightForTextView = tmpCell.textView.frame.size.height
tableView.beginUpdates()
tableView.endUpdates()
任何一個NOW的如何實現這個問題? 或我的方式有什麼問題?
非常感謝