For oc Viewcontroller *VC = [[Viewcontroller alloc] init], the method defaults to loading a xib file with the same name as view. But in Swift viewcontroller.init () he does not load the Xib by default on IOS8, while in iOS 9 the xib is loaded by default.
The previous period of time project has been in the IOS9 + environment of the real machine debugging, today take IOS8 debugging, found that all the use of xib created Viewcontroller are not available. Even when it comes to an optional type. Helpless, build a test demo, find the problem. Finally solved the problem.
1, in Appdelegate, if you write this, because storyboard is not used, and xib is used, the content in Xib cannot be displayed in IOS8.
[OBJC] View Plain copy func application (application: uiapplication, Didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]? -> Bool { self.window = uiwindow (Frame: uiscreen.mainscreen (). bounds) self.window? Makekeyandvisible () let vc = myviewcontroller () let navigation = uinavigationcontroller.init (rootViewController: VC) self.window? rootviewcontroller = navigation  &NBsp; return true }
2, we need to use the nib method when we find the Xib and initialize it. This will show normal.
[OBJC] View Plain copy func application (application: uiapplication, Didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]? -> Bool { self.window = uiwindow (Frame: uiscreen.mainscreen (). bounds) self.window? Makekeyandvisible () let vc: myviewcontroller? = myviewcontroller (nibName: " Myviewcontroller ", bundle: nil) let Navigation = uinavigationcontroller.init (rootviewcontroller: vc!) self.window? Rootviewcontroller = navigation return true }
[OBJC] View Plain copy class myviewcontroller: uiviewcontroller { @IBOutlet weak var titleLab: UILabel! override init (nibname nibnameornil: string!, bundle nibbundleornil: nsbundle!) { super.init (Nibname: nibnameornil, bundle: nibbundleornil) } required init? (Coder adecoder: nscoder) { FatalError ("Init (coder:) has not been implemented") } override func viewdidload () { super.viewdidload () titlelab.text = "What is this ah ... " }