我正在尝试为我的 UITableViewCell
设置自定义高度。在 Xcode 中,我给了它一个自定义高度并添加了一个 UImageView
subview ,它看起来不错。然而,在运行时,单元格的高度会回落到默认值,并且我的图像被严重裁剪。
我已经将委托(delegate)设置为使用动态高度,并且在 Xcode 中为单元格提供了自定义高度,并且我的图像设置为宽高比填充。我不确定我还缺少什么。
这是我的VC:
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
switch indexPath.section {
case 0:
return UITableViewAutomaticDimension
default: ()
return 50
}
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
switch indexPath.section {
case 0:
return 300
default: ()
return 50
}
}
最佳答案
当然,这不是一个很好且清晰的答案,但设置自动布局可能存在问题。通常很难在这里提供所有数据的布局和约束,因此您最好检查一些 Material ,例如 this 。然后检查您的代码。
关于ios - UITableViewCell自定义高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34115464/