Swift 3 中删除了 preferredStatusBarStyle 吗? [英] preferredStatusBarStyle removed in Swift 3?

查看:15
本文介绍了Swift 3 中删除了 preferredStatusBarStyle 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我最近刚刚更新到 Xcode 8,我刚刚收到以下代码的错误.

so I recently just updated to Xcode 8 and I just got this error for the following code.

错误在于该方法没有覆盖其超类中的任何方法.

The error is that the method doesn't override any method from it's superclasses.

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return UIStatusBarStyle.lightContent
}

非常感谢您的帮助,谢谢!

I would really appreciate help, thanks!

推荐答案

在 iOS 10 中,preferredStatusBarStyle 是一个属性,而不是一个方法.因此,不是像您那样使用 func 声明覆盖它,而是使用 var 声明覆盖 getter:

In iOS 10, preferredStatusBarStyle is a property, not a method. So instead of overriding it with a func declaration as you've done, you override the getter with a var declaration:

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

此处 Swift 编译器的错误消息可能会更好——因为它似乎知道您的覆盖 func 应该覆盖一个属性,它可能会提供它作为修复它.我建议 向 Swift 开源提交错误.

The Swift compiler's error message here could probably be better — since it seems to know your override func is supposed to cover a property, it could probably offer that as a fix-it. I'd recommend filing a bug to Swift open source.

注意:在 iOS 12 中,您可能还需要在 Info.plist 中设置 UIViewControllerBasedStatusBarAppearance(又名基于视图控制器的状态栏外观")标志.并检查您的视图控制器层次结构,因为导航和拆分视图等容器视图控制器可能不会从其子级传播此信息.

Note: in iOS 12, you may also need to set the UIViewControllerBasedStatusBarAppearance (aka "View controller-based status bar appearance") flag in your Info.plist. And check your view controller hierarchy, as container view controllers like navigation and split view might not propagate this from their children.

这篇关于Swift 3 中删除了 preferredStatusBarStyle 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆