我有一个自动调整大小的表格,我想强制设置一些单元格的高度以仅显示标题。
我的代码中有这个:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 140
而且,我尝试添加下面的代码片段,但自动调整大小效果停止工作:
tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
请在下面找到我要完成的表格的屏幕截图。
最佳答案
如果您想继续按照自己的方式做事:
删除
tableView.rowHeight = UITableViewAutomaticDimension
,因为在实现heightForRowAtIndexPath
之后它什么都不做。实现
heightForRowAtIndexPath
方法,该方法将为所选单元格和其他单元格返回特殊高度 -UITableViewAutomaticDimension
关于ios - Swift - 在设置 UITableViewAutomaticDimension 时强制设置单元格大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40128639/