我想在详细 View Controller 中自行调整单元格的大小。我该怎么做呢?我查阅了很多教程,并且我能够在其他应用程序上自行调整大小,但在这里不行。那么,我该怎么做,错误是什么?
谢谢。
这是我的约束的图像:
我已在 View Controller 的 viewDidLoad()
方法中实现了此代码:
tableView.estimatedRowHeight = 400.0
tableView.rowHeight = UITableViewAutomaticDimension
我已经在详细 View Controller 类中实现了此代码:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 500
}
我使用的语言是 Swift。
这是它最初的样子的图像:Click here
最佳答案
您已正确设置方法自动调整其内容大小:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
在这种情况下,您应该为单元格的每个元素设置正确的约束,以便正确自动调整大小。
关于ios - 如何自行调整单元格大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35408051/