[英]Swift app renders a black screen on ios 8.x
I have a very basic app:我有一个非常基本的应用程序:
When I run my app on iOS 9 no problem.当我在 iOS 9 上运行我的应用程序时没问题。 On iOS 8.x: black screen.
在 iOS 8.x 上:黑屏。
here is my AppDelegate这是我的 AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let frame = UIScreen.mainScreen().bounds
window = UIWindow(frame: frame)
let rootView: HomeViewController = HomeViewController()
if let window = self.window{
window.rootViewController = rootView
window.makeKeyAndVisible()
}
BITHockeyManager.sharedHockeyManager().configureWithIdentifier(Config.HOCKEY_APP_IDENTIFIER);
BITHockeyManager.sharedHockeyManager().startManager();
BITHockeyManager.sharedHockeyManager().authenticator.authenticateInstallation();
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
return true
}
Any ideas?有任何想法吗?
I had same bug in 8.0 for loading view controller from xib files.我在 8.0 中有同样的错误,用于从 xib 文件加载视图控制器。 And that helped me:
这对我有帮助:
let controller = HomeViewController(nibName: "HomeViewController", bundle: NSBundle.mainBundle())
NSBundle.mainBundle()
was the key that helped me. NSBundle.mainBundle()
是帮助我的关键。 By default he couldn't find xib file in the bundle默认情况下,他无法在包中找到 xib 文件
I had this bug with Xcode 8.3.3 and target iOS 8.0.我在 Xcode 8.3.3 和目标 iOS 8.0 上有这个错误。
This bug occurs when the developer create a UIWindow.当开发人员创建 UIWindow 时会发生此错误。
If you are using Swift 3.1, use this:如果您使用的是 Swift 3.1,请使用以下命令:
self.window = UIWindow()
self.window?.makeKeyAndVisible()
self.window?.frame = UIScreen.main.bounds
self.window?.rootViewController = MyViewController(nibName: "MyViewController", bundle: Bundle.main)
Are you customizing the HomeViewController in the XIB or StoryBoard?您是在 XIB 或 StoryBoard 中自定义 HomeViewController 吗?
Because you are not using then to load the HomeViewController object因为你没有使用 then 来加载 HomeViewController 对象
let rootView = HomeViewController(nibName: "HomeViewController", bundle: nil)
or customize a init method或者自定义一个 init 方法
convenience init() {
self.init(nibName: "HomeViewController", bundle: nil)
}
and use like before并像以前一样使用
let rootView = HomeViewController()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.