我有一個UITableView(表1)。在UITableView Cell中我有另一個UITableView(表2)。TableView單元格動態高度
在Table 2
行的高度是UITableViewAutomaticDimension
。
我的要求是 - 我想這Table 2
不應滾動,並採取充分的高度,每個裏面it.So的行數,按本Table 2
的高度,我需要設置Table 1
的行高。
我使用表2的contentSize.height,但它不工作。我搜查了很多,但什麼也沒找到。
代碼:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
let cell = tableView_First.dequeueReusableCell(withIdentifier: "SecondTableViewCell") as! SecondTableViewCell
return cell.second_TableView.contentSize.height
}
更新:
我已經調試的代碼,發現表2的電池的估計高特效表1的單元格的高度。即,如果表2的單元的估計高度是100並且這些單元是5個單元。然後這cell.second_TableView.contentSize.height
給我500.哪個是錯誤的。因爲細胞有不同的高度10,20,30,40,10。
任何建議,將不勝感激。
謝謝!
感謝您的回答。但是這段代碼給了我「Bad _Access」。我檢查了錯誤https://stackoverflow.com/questions/35931478/why-tableview-cellforrowatindexpathindexpath-give-me-a-bad-access-error。你能建議現在做什麼? – Amanpreet