简体   繁体   中英

How do I use the delegate to dictate which view controller behaves as the initial view controller?

I am trying to add to my app delegate file the code that will allow me to segue directly to my "Camera VC" if the user is logged in and to the "loginVC" if the user is not logged in. To be honest, I am very lost on how to do this and any help would be hugely appreciated.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    var isLoggedIn: Bool?

    let storyboardId: String = (isLoggedIn != nil) ? "loginVC" : "CameraVC"

    self.window?.rootViewController?.storyboard?.instantiateViewControllerWithIdentifier(storyboardId as String)

    return true
}

In Storyboard each UIViewController has flag to be initialViewController.U need to set it right. Imho best solution is to wrap both controllers in some container controller (ie UINavigationController) and programatically push (pop) to write contained UIViewController.

example in objC

if(![SettingsUtility isUserAuthorized])
    {
        [self showLoginViewController];
    }

    -(void)showLoginViewController
    {
        [self.navigationController performSegueWithIdentifier:@"showLoginViewController" sender:self];
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM