3

since I've been unable to do even one succesfull merge with storyboard, I'm trying to switch to xib files. I'm trying to set one xib file as initialViewController as you do in storyboard, so first I've disabled that property in storyboard. Following some examples from google, I've made an extension that is supposed to return a xib file:

extension UIViewController {
    class func loadFromNibNamed(nibNamed: String, bundle : NSBundle? = nil) -> UIViewController? {
        return UINib(
            nibName: nibNamed,
            bundle: bundle
            ).instantiateWithOwner(nil, options: nil)[0] as? UIViewController
    }

and then called that class function from the app delegate and try to load the xib file as root view controller like this:

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.


        let mainView = UIViewController.loadFromNibNamed("MainView")
        //window?.addSubview(mainView!)
        self.window?.rootViewController = mainView

        return true
    }

My xib file name is MainView.xib, I have a UIView and a MainViewController on it, MainViewController inherits from ViewController and it's still empty:

enter image description here

enter image description here

enter image description here

Whatever I try I allways get the same error message:

Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?

1 Answer 1

4

You still have the project set up to use the Main.storyboard file. In the project / general tab, you need to clear this section:

enter image description here

If you do this you will also need to create the UIWindow yourself and set the app delegate's window property, as this is not created if you don't use a storyboard. See How to create an Empty Application in Xcode 6 without Storyboard for details.

3
  • 1
    as i write bellow answer i did not change anythings in general tab as you said. i just did code in main didFinishLaunchingWithOptions that set the rootviewcontroller then why we need to do clear main Interface as you said?? May 13, 2016 at 10:36
  • 1
    I've managed to start the app thanks to your help but now I have a black screen despite I've added a text label with white tint color and a viewController from the custom class mainViewController and deleted the UIView. Can you help me to start interacting with the xib file?
    – Alfro
    May 13, 2016 at 10:37
  • 1
    Because that loads the storyboard, and without an entry point your storyboard is not valid. Having the main interface value set means that the storyboard will be loaded before didFinishLaunchingWithOptions is called.
    – jrturton
    May 13, 2016 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.