Storyboard - go back to tab bar controller from modal view controller

1.1k Views Asked by At

I have a tab bar controlled application.

And I have a flow that goes something like this:-

Tab 1 View Controller (initial view controller) - "presented modally" View controller - "pushed" View Controller 2 - "pushed" View Controller 3 - "presented modally" View Controller 4

Basically, it is Modal - Push - Push - Modal

Now, I want to go back to Tab 1 View Controller(initial view controller) from View Controller 4 (that was presented modally).

View controller 4 should have a "back button" which when pressed will lead me back to Tab 1 View Controller.

How do I do that? I tried:-

  1. Creating a whole new UIWindow and placed things back. Problem is the back button which I placed on View Controller 4 comes back on Tab 1 View Controller. Weird. Tried removing it with various methods, didn't go away.

  2. Use the popToViewController method, but the navigation controller is different because of last modal view controller.

Any clues on how to solve this?

2

There are 2 best solutions below

0
On BEST ANSWER

Okay so I solved it. I needed to climb back down the ladder.

Dismiss self.navigationController.presentingViewController.presentingViewController, which was pointing to UITabBarController, where self.navigationController is from View Controller no. 4 (the last modal view controller).

2
On

You should try this on the button that leads to the first tab view controller

UIStoryboard *mySB = [UIStoryboard storyboardWithName:@"[StoryBoardFileName]" bundle:nil];
            UIViewController *vc = [mySB instantiateViewControllerWithIdentifier:@"[ViewControllerIdentifier]"];
            [self presentViewController:vc animated:YES completion:nil];

hope it helps