1
今天我又遇到了其他問題。我想在viewDidLoad時從故事板導航到xib文件。它導航,但我得到了黑屏。如何在swift中從storyboard導航到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)
這是我得到的:
我TutorialScreen.xib: