Search code examples
iosobjective-ccocoa-touchseguestack-unwinding

iOS unwind to view not loaded


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 ?


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.