ios - 错误的 UITableViewAutomaticDimension 高度,仅适用于 iPhone 5

标签 ios swift uitableview

我的tableview单元格的高度是自动计算的

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = UITableViewAutomaticDimension

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
     return UITableViewAutomaticDimension
}

它在除 iPhone 5 以外的所有设备上都运行良好。在实际设备和模拟器中进行了尝试,结果相同:

enter image description here

知道为什么会这样吗? iOS 10.3.1

最佳答案

tableView.estimatedRowHeight = UITableViewAutomaticDimension 仅适用于 iOS 11。

改用真实值:

if #available(iOS 11.0, *) {
    tableView.estimatedRowHeight = UITableViewAutomaticDimension
} else {
    tableView.estimatedRowHeight = 200
}

关于ios - 错误的 UITableViewAutomaticDimension 高度,仅适用于 iPhone 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51724304/

相关文章:

ios - 在 Popover 中搜索的 UITableViewController 有奇怪的动画

ios - 仅自动旋转 MpMoviePlayerControler iOS 6

ios - UITableview 编辑模式上的删除控制按钮不起作用

objective-c - 如何从devicename(UITableViewCell)中的tableview中显示蓝牙支持的服务?

ios - NSKeyedArchiver 调用encodeObject 时如何捕获 EXC_BAD_ACCESS

ios - 在 Swift 中获取两个日期(月/日/小时/分钟/秒)之间的差异

swift - 使用 UIActivityViewController 共享您的设备屏幕

Swift 冲突的 UIPickerView

swift - 在 iCloud 数据库中上传 Assets 之前发送的记录更新推送通知

iphone - 是否可以将 UIBarButtonItem 作为单元格accessoryView?