首页 > 解决方案 > Xcode 11 - UITableViewAutomaticDimension 或 UITableView.automaticDimension 上的 Swift 编译器错误

问题描述

升级到 Xcode 11 后我刚得到一个Swift Compiler Error。我在我的 UIViewController 中使用 UITableView。所以我将 UITableView 委托给 UIView。我正在使用 tableview 单元格的自动高度UITableView.automaticDimension(这个工作很好,因为我使用的是 Xcode 8)。并且 Xcode 错误建议出现说'automaticDimension' has been renamed to 'UITableViewAutomaticDimension'。所以我按照建议将我的代码更改为UITableViewAutomaticDimension. 'UITableViewAutomaticDimension' has been renamed to 'UITableView.automaticDimension'构建后几秒钟,如果我反之亦然,则新建议会出现在当前代码上,依此类推。有没有人和我一样的问题?Xcode 截图

标签: swiftxcodeuitableviewxcode11.2

解决方案


// Swift 4.2 onwards
table.rowHeight = UITableView.automaticDimension
table.estimatedRowHeight = UITableView.automaticDimension

// Swift 4.1 and below
table.rowHeight = UITableViewAutomaticDimension
table.estimatedRowHeight = UITableViewAutomaticDimension

推荐阅读