【问题标题】:Xcode 11 - Swift Compiler Error on UITableViewAutomaticDimension OR UITableView.automaticDimensionXcode 11 - UITableViewAutomaticDimension 或 UITableView.automaticDimension 上的 Swift 编译器错误
【发布时间】:2023-03-17 03:42:01
【问题描述】:

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

【问题讨论】:

    标签: swift xcode uitableview xcode11.2


    【解决方案1】:
    // Swift 4.2 onwards
    table.rowHeight = UITableView.automaticDimension
    table.estimatedRowHeight = UITableView.automaticDimension
    
    // Swift 4.1 and below
    table.rowHeight = UITableViewAutomaticDimension
    table.estimatedRowHeight = UITableViewAutomaticDimension
    

    【讨论】:

    • 感谢您的回答,但即使我将代码更改为UITableView.automaticDimension,错误建议也没有消失。
    • 发布答案时,请说明您的答案如何解决问题,而不仅仅是发布一段代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 2017-02-23
    相关资源
    最近更新 更多