Question

I'm in front of a little problem :

I have something like that when launching the app :

(1) Splash view --> I am logged ? --> (3) HomeView | else (2) Login view

So when I log, then I go to the home view. And when I logout, I can unwind to the login view because i came from it.

BUT if I don't pass from the login view and redirect directly to the home view, I can't unwind to login view when logout.

Someone know a solution about this ?

Was it helpful?

Solution

I just put my logic here:
Take/add one viewController such like, DummyViewController as rootViewController of your app. in the DummyViewController's viewWillAppear method put logic like a

- (void)viewWillAppear:(BOOL)animated 
{
    [super viewWillAppear:animated];

    if(login == YES)
    {
       //go to home screen
    }
    else
    {
      // go to login screen
    }
}

In DummyViewController you just need to write code in viewWillAppear not anymore. If you want to Logout then just call

[self.navigationController popToRootViewControllerAnimated:YES]; 

And viewWillAppear method of DummyViewController will manage your screen based on login status.

OTHER TIPS

You can use NSNotificationCenter to notify your root class when logout done. Then pop to your rootViewController

If you are using UINavigationController, Just present your login controller on NavigationController's RootViewController as like below

-(void)logoutNotification
{
logout = YES;
}

-(void)viewDidAppear:(BOOL)animated
{
    if (logout)
    {        
        AuthController * auth = [[AuthController alloc] init];

        [self presentViewController:auth animated:NO completion:^{

        }];

        logout = NO;

        auth = nil;
    }
}

Maybe is a bit dummy way to do it, but you can simply ALWAYS load the login view and delegate to it the "I'm logged?" check. You can load it hidden or with a waiting sign or whatever... This way you have it already loaded when you logout.

Without seeing your code I can't show you how to, but I guess the logic is enough.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top