1
votes

When user start the app, I'll check the auth status, and show different ViewControler

Logged in -> Main ViewController -> Will pushViewController or presentViewController according to user action

Need Log in -> SignIn ViewController -> Main ViewController -> Will pushViewController or presentViewController according to user action

My question is how to back to SignIn ViewController when user want to sign out.

Method One:

Current ViewController -> presentViewController/pushViewController SignIn ViewController

Issue: Previous ViewControllers are still in memory

Method Two:

Current ViewController -> popToRootViewControllerAnimated -> presentViewController/pushViewController SignIn ViewController

Issue: If the user logged in before, the RootViewController will be Main ViewController, we can't release the Main ViewController with the method.

Method Three:

[[[[UIApplication sharedApplication] delegate] window] setRootViewController:signinNavigationController];

Issue: No animate, and looks previous ViewController are still in memory.

2
Use storyboard and unwind segues. 2015 year already! - Cy-4AH
@Cy-4AH, thanks for your suggestion, but I have to say that it's too late for my application... - Yuwen Yan

2 Answers

1
votes

You can use Unwind segue in storyboard. Refer this link for more details: http://spin.atomicobject.com/2014/10/25/ios-unwind-segues/

Programatically, When you press logout button Call appDelegate function:

func showLoginController() {
    //For Story board use this line
    var loginController:LoginViewController = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("loginViewControllerIdentifier") as! LoginViewController
    //for xib file use this line
    var loginController:LoginViewController = UINib(nibName: "loginViewController", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as? LoginViewController

    AppDelegate.sharedAppDelegate().window?.rootViewController = loginController
}
0
votes

you can remove your previous viewcontroller from your signinNavigationController (NavigationController)stack.

say as

NSMutableArray *navArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];

// This is just for remove all view controller from navigation stack. [navArray removeObjectAtIndex: 0];

// And again Adding the stack to the navigation stack.

self.navigationController.viewControllers = navArray;