我有多个具有不同行高的动态单元格。因此,我尝试使用estimatedHeightForRowAtIndexPath 方法更新行高
这是我的代码:
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
switch indexPath.row {
case 0:
return 132
case 1:
return 66
case 2:
return 80
case 3:
return 70
case 4:
return 50
case 5:
return 60
case 6:
return 60
default:
return 60
}
}
但是,行高不会更新。它使用 Storyboard 中的估计行高。有什么问题吗?
最佳答案
在您的情况下,您应该使用方法heightForRowAtIndexPath
。
当您想使用自动调整单元格大小时,请使用estimatedHeightForRowAtIndexPath
。
Providing an estimate the height of rows can improve the user experience when loading the table view. If the table contains variable height rows, it might be expensive to calculate all their heights and so lead to a longer load time. Using estimation allows you to defer some of the cost of geometry calculation from load time to scrolling time.
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
switch indexPath.row {
case 0:
return 132
case 1:
return 66
case 2:
return 80
case 3:
return 70
case 4:
return 50
case 5:
return 60
case 6:
return 60
default:
return 60
}
}
关于ios - estimatedHeightForRowAtIndexPath 不更新行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39333134/