3

I have an app whose structure is defined in the attached image.

Basically, I have a Sign In View Controller as the Root View Controller. When user signs in, app they go to the TabbarController, from where they go to the Home View Controller. And there are three more tabs. Now there is a Log Out Button tapping on which user should go to the Sign In View Controller but if I write code to pop to Root View Controller they will go to the Root View Controller of any tab but not on the Sign In Screen.

enter image description here

How can I POP to the Sign In View Controller?

I don't want to create new Object of SignInViewController so Push won't work for me and moreover, it will cost lots of memory.

I am using Swift in Xcode 6.1

double-beep
  • 5,031
  • 17
  • 33
  • 41
Developer
  • 6,375
  • 12
  • 58
  • 92
  • 1
    You can use an unwind segue. Check this: http://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-do-you-use-them – gabriel Feb 18 '15 at 09:10
  • you can use ' [self.navigationController popToRootViewControllerAnimated:True]' – Ashok Londhe Feb 18 '15 at 09:45
  • @Ashok Please see this line I have mentioned in my question.------- "if I write code to pop to Root View Controller to he will go to the Root View Controller of any tab but not on the Sign In Screen. -----" – Developer Feb 18 '15 at 09:53
  • In which View Controller you have embedded Navigation Controller. – Ashok Londhe Feb 18 '15 at 10:07
  • and i think your RootViewController is SignScreenViewController – Ashok Londhe Feb 18 '15 at 10:08
  • what is the `SingInViewController` exactly? a navigation-controller? a view-controller? – holex Feb 18 '15 at 10:13
  • @holex Here is the image of SignInViewController, how I have integrated! https://www.dropbox.com/s/6ymnz12oibujxk0/Screen%20Shot%202015-02-18%20at%205.08.11%20PM.png?dl=0 – Developer Feb 18 '15 at 11:40
  • did you ever figure this out? – Serge Pedroza Jul 16 '15 at 21:49
  • 1
    @SurgePedroza Yes, I found the solution. I created one global object of Navigation Controller and assigned it to the object of Navigation Controller in SignInViewController. Then I called pushToViewController: and passed that global object. Let me know if you still have any doubt! :-) – Developer Jul 24 '15 at 08:27

2 Answers2

1

You must have to make SignInViewController as a root view controller.

  1. delete the login credentials.
  2. and load the SignInViewController as a rootviewcontroller.

NOTE: in my scenario workflow will work best in ARC mode. because in ARC mode we don't have to release all view controllers you have loaded in memory.

Stranger
  • 96
  • 7
1

Here is my implementation of changing rootviewcontroller with animation. This method defined in AppDelegate class. Do not forget to assign storyboardid to your desired ViewController.

 - (void)changeRootViewControllerWithID:(NSString *)storyboardId
    {
        UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];

        UINavigationController * newRootViewController = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:storyboardId];

        [newRootViewController view];

        [UIView transitionFromView:self.window.rootViewController.view
                                                toView:newRootViewController.view
                                            duration:0.65f
                                             options:UIViewAnimationOptionTransitionFlipFromRight
                                        completion:^(BOOL finished){
                        self.window.rootViewController = newRootViewController;
                                        }];

    }
Neil Galiaskarov
  • 5,015
  • 2
  • 27
  • 46