0

i am trying to add a login screen to my app but when i tried changing the initial view controller to the login screen but when i change the initial view controller pointer it has no effect. I have tried the suggestions in:

iOS 7 - Failing to instantiate default view controller but they did not work for me. the first screen under the navigation controller is instead showing which was the intended initial view before the login was added.

Storyboard screenshot

App Delegate

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

    let centerViewController = mainStoryboard.instantiateViewControllerWithIdentifier("ViewController") as!ViewController

    let drawerViewController = mainStoryboard.instantiateViewControllerWithIdentifier("DrawerViewController") as!DrawerViewController

    let leftSideNav = UINavigationController(rootViewController: drawerViewController)
    let centerNav = UINavigationController(rootViewController: centerViewController)

    centerContainer = MMDrawerController(centerViewController: centerNav, leftDrawerViewController: leftSideNav)

    centerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView;
    centerContainer!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView;

    //works when i comment out this but navigation does not work then
    //window!.rootViewController = centerContainer
    window!.makeKeyAndVisible()



    return true
}
Community
  • 1
  • 1
Lonergan6275
  • 1,938
  • 6
  • 32
  • 63
  • Check `application:didFinishLaunchingWithOptions:`, maybe u set the window and rootViewController with code already. – Justlike Jan 28 '16 at 11:12
  • @Justlike i have added code from the Delegate class needed for the navigation – Lonergan6275 Jan 28 '16 at 11:20
  • 1
    The config of storyboard would be **ignored** if you config the `window` with code. – Justlike Jan 28 '16 at 11:23
  • 2
    See, `window!.rootViewController = centerContainer`. So it is. `centerContainer` will be `the initial view controller` whatever you set with storyboard. @Lonergan6275 – Justlike Jan 28 '16 at 11:28
  • @Justlike ya i just noticed that but if i comment it out the initial view works but the nav drawer no longer works? should it work if I set `window!.rootViewController = centerContainer` after login? – Lonergan6275 Jan 28 '16 at 11:30
  • 1
    Adjust your storyboard like this. @Lonergan6275 [http://i.stack.imgur.com/eYjkS.png](http://i.stack.imgur.com/eYjkS.png) – Justlike Jan 28 '16 at 11:32
  • @Justlike If i do as you suggest wont the login be part of the main navigation then? i want login before the user sees the rest of the app and shouldnt be in the menu after that – Lonergan6275 Jan 28 '16 at 11:34
  • 1
    As you said, set `window!.rootViewController = centerContainer` after login will work. – Justlike Jan 28 '16 at 11:37

0 Answers0