ios - Swift 2 upgrade Swift 3 编译报错很多方法如willTransitionToTraitCollection :newCollection:withTransitionCoordinator

标签 ios swift uiviewcontroller swift3

当我使用swift 3运行一些旧代码,并将它们转换为最新的swift 3时,我发现方法编译错误

    override func willTransitionToTraitCollection( newCollection: UITraitCollection,
      withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
}

编译器告诉我“方法不会覆盖其父类(super class)中的任何方法”

我应该导入一些模块吗?

最佳答案

在我的 Xcode 8 beta 3 的 Swift 编辑器中:

class MyViewController: UIViewController {
    //Wait hear  ↓
    willTransition
}

我有这个建议:

class ViewController: UIViewController {
    //Wait hear  ↓
    override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
        <#code#>
    }
}

(您需要删除所有其他语法错误以获得更好的建议。)

无论如何,你不应该什么都自己做。让 Swift 做到这一点。


willTransitionToTraitCollection:withTransitionCoordinator: 的新文档在这里:

willTransitionToTraitCollection:withTransitionCoordinator:

关于ios - Swift 2 upgrade Swift 3 编译报错很多方法如willTransitionToTraitCollection :newCollection:withTransitionCoordinator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38631985/

相关文章:

ios - 拒绝问题 : "We are not able to continue because we need a demo QR code or AR marker (image) to fully assess your app features."

arrays - 删除 Swift 数组中所有出现的值

ios - swift3 中带有自定义标题的自定义导航后退按钮

swift - UIWebView 不滚动

ios - 使用日期 Swift 3 对字典数组进行排序

ios - Swift 如何检查 API 是否不可用

swift - 在 SwiftUI 中设置切换颜色

ios - 显示没有 segue 的弹出 View Controller

iphone - 当点击 backBarButtonItem 时,有没有办法阻止 UIViewController 从 UINavigationController 的堆栈中弹出?

ios - 滚动 UITableView 时的值变化