【发布时间】:2016-03-10 08:55:28
【问题描述】:
我正在尝试计算具有动态增加单元格的 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 混淆,因此您只需删除它的实现即可获得好运。 ——魏文
那么,尽管单元格大小是动态的,有什么方法可以让我获得正确的内容大小?
【问题讨论】:
-
嘿,你找到解决这个问题的方法了吗?我也遇到过同样的问题
标签: ios swift uitableview