[英]Calculating content Size of Table View with dynamic increasing cell
我正在嘗試計算tableView的內容大小高度,它具有動態增加的單元格。 為此,我正在編寫代碼 -
override func viewDidLoad()
{
super.viewDidLoad()
self.tableView.estimatedRowHeight = 150
self.tableView.rowHeight = UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as! MostLikedTVCscnd
cell.image.image = imageArr[indexPath.row] as? UIImage
cell.aboutLbl.text = labelArr[indexPath.row] as? String
let contentSizeHeight = tableView.contentSize.height//But here I am not getting the proper height
return cell
}
我在計算tableView內容大小的問題中檢查了一個答案 - https://stackoverflow.com/a/17939938/5395919
注意那些不能使用它的人 - tableView:estimatedHeightForRowAtIndexPath混淆了contentSize,所以你可以通過刪除你的實現來獲得運氣。 - weienw
那么,盡管有動態單元格大小,我還能獲得正確的內容大小嗎?
只要表視圖的內容大小發生變化,您就可以使用鍵值觀察(KVO)進行通知。 這可能會或可能不適用於您正在嘗試的操作。 我只是不清楚你想要獲得什么,但我認為嘗試在cellForRowAtIndexPath中使用它並不好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.