如何在swift中从storyboard导航到xib文件?

时间:2015-05-08 02:16:05

标签: swift navigation storyboard xib

今天我又遇到了其他问题。我想在viewDidLoad时从我的故事板导航到xib文件。它导航但我得到黑屏。

我的xib文件:TutorialScreen.xib

控制xib文件的类:TutorialScreenViewController.swift

我在TutorialScreenViewController.swift中的代码:

 class TutorialScreenViewController : UIViewController {

@IBOutlet var mainView: UIView!


required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    mainView = UIView()
    super.init(nibName: nil, bundle: nil)
}

convenience init() {
    self.init(nibName: nil, bundle: nil)
}


}

其他类中的代码viewDidLoad:

let tutorialScreen = TutorialScreenViewController(nibName: "TutorialScreen", bundle: nil) as TutorialScreenViewController

        self.navigationController?.presentViewController(tutorialScreen, animated: false, completion: nil)

这是我得到的:

I got this black screen

My TutorialScreen.xib:

enter image description here

1 个答案:

答案 0 :(得分:1)

我发现我做错了。以下是我编辑的内容:

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
mainView = UIView()
super.init(nibName: nil, bundle: nil)
}

编辑后:

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    mainView = UIView()
    super.init(nibName: nibNameOrNil , bundle: nibBundleOrNil)
}

那就是!!!!!!