加载ViewController Swift-黑屏 [英] Load ViewController Swift - Black Screen

查看:306
本文介绍了加载ViewController Swift-黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在单击按钮时简单地加载新的ViewController及其关联的xib,但是在加载新视图后,屏幕变为黑色.单击该按钮时,将调用以下方法:

Im trying to simply load a new ViewController and its associated xib when a button is clicked, but the screen becomes black after the new view is loaded. When the button is clicked the following method is called:

    let vc = MainViewController()
    self.showViewController(vc, sender: nil)

我能够调试并看到我们正在进入新的"MainViewController"类的viewDidLoad方法,但是UI无法呈现,并且屏幕为黑色.我已经将MainViewController.xib的文件所有者设置为MainViewController.swift类,但是什么也没有发生.在类中也将调用super(). MainViewController.xib中唯一的东西是MapView.

I am able to debug and see that we are jumping into the viewDidLoad method of the new "MainViewController" class, but the UI is not rendering and the screen is black. I have set the File's Owner of MainViewController.xib to the MainViewController.swift class, but nothing happens. super() is being called in the class as well. The only thing in MainViewController.xib is a MapView.

推荐答案

尝试一下,您缺少xib的名称...

Try this, your are missing name of xib...

 let vc = MainViewController(nibName: "MainViewController", bundle: nil) // Enter you nibname in this 
 self.showViewController(vc, sender: nil)

谢谢:)

这篇关于加载ViewController Swift-黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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