2
votes

I have the following workflow defined within my iPhone project storyboard:

  • Login view controller is set as root view controller in a storyboard.
  • Login has a separate workflow for login and setting up account.
  • Both workflows end up modally presenting tab bar with the main app content
  • For subsequent app launches, I programmatically determine the correct controller to instantiate in appDidFinishLaunching:
  • For subsequent app use the tab bar with main content is the root view controller (programmatically set)

Now I would like to implement a "logout" process - a button wipes all the user data and brings the user back to the original "login/set up account" screen.

I'm running into an issue where due to multiple states of the application I need to have multiple paths to return to the home screen. For example:

                      UIViewController* parent = self.presentingViewController;
                      UIViewController* grandparent = self.presentingViewController;
                      [self.presentingViewController dismissViewControllerAnimated:YES completion:^{
                          DLog(@"first dismiss");

                          DLog(@"%@",parent);
                          DLog(@"%@",grandparent);

                          [parent dismissViewControllerAnimated:YES completion:^{
                              DLog(@"second dismiss");
                              [grandparent.navigationController popToRootViewControllerAnimated:YES];
                          }];
                      }];

How would I go about implementing the login/logout logic defined above?

Is there a correct way to completely collapse the view hierarchy that is currently that is currently on screen and replace it with another one?

I'm thinking of this one:

 [self.window setRootViewController:tabBarViewController];

But am not sure if this will properly unload all resources used by the old rootViewController stack that I'm detaching.

1
I have a similar setup, made slightly more complex by having the tab bar controller over a slide-out (hamburger) menu. This answer worked wonders for me: stackoverflow.com/questions/10273910/… Essentially it's a matter of keeping hold of the storyboard when your app launches and reverting to the start of the storyboard when needed. It really doesn't matter where you are in your application.andyb

1 Answers

-1
votes

Use NSUserDefault to store the login value, check userdefault before calling any viewController ... At signout delete value from Userdefaults or use this code at signout

NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];