2015-05-08 84 views
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) 

這是我得到的:

I got this black screen

我TutorialScreen.xib:

enter image description here

回答

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) 
} 

就是這樣!!!!!!

相關問題