0

I'm setting the rootViewController of the window programatically, like this (didFinishLaunchingWithOptions under AppDelegate's application method):

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootViewController = storyboard.instantiateViewControllerWithIdentifier("loginScreen")

window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.makeKeyAndVisible()

if let window = window {
    window.rootViewController = rootViewController
}

Am I still required to go in the Interface Builder and set that controller as initial view controller? I get Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set? If I set an entry point I have no problem and the error disappears. I want to know what is the correct way of programatically loading views. It's weird to set the rootViewController both programatically and by interface builder. Note that I am a beginner.

robertsan
  • 1,591
  • 3
  • 14
  • 26
  • see this http://stackoverflow.com/questions/20875823/ios-7-failing-to-instantiate-default-view-controller – Anbu.Karthik Sep 08 '16 at 10:27
  • duplicate of - http://stackoverflow.com/questions/20875823/ios-7-failing-to-instantiate-default-view-controller – Anupam Mishra Sep 08 '16 at 10:30
  • I've almost run out of solutions. I've already checked those questions so I don't think this is a duplicate. – robertsan Sep 08 '16 at 10:31
  • 1
    If you're using storyboard anyway, forget the code and set the entry in Interface Builder. – vadian Sep 08 '16 at 10:35
  • I won't use Segues so setting the rootViewController programatically would do the trick. I think that setting the entry back will be the final decision. It's just weird, this is why I asked this. – robertsan Sep 08 '16 at 10:37
  • As you mention *I am a beginner* why do you want to start with the advanced stuff? ;-) – vadian Sep 08 '16 at 11:20
  • I'm on iOS since one year. I coded many applications, but I still consider myself a beginner if I encounter this kind of problems. :) – robertsan Sep 08 '16 at 15:39

1 Answers1

0

Please check the tick mark 'Is Initial View Controller' in controller properties, And then clean and run. If still exists, please try this

   UIApplication.sharedApplication().keyWindow?.rootViewController = viewController;
Narendra G
  • 491
  • 4
  • 9