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

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

问题描述

所以我最近刚刚更新到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中,

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编译器错误消息可能会更好-因为似乎知道您的重写功能应该覆盖某个属性,因此它可能会作为修复程序来提供.我建议将错误提交给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.

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

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