2

I have a UITabBarController in my application.

I would like to present from one tab, another UIViewController.

So I wrote in ViewControllerA (which is a tab in the tabviewcontroller):

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
MyViewController *chooseTemplateController = [storyboard instantiateViewControllerWithIdentifier:@"myController"];
[self.tabBarController presentViewController:myController animated:NO completion:nil];

This shows MyViewController nicely.

However, how can I dismiss MyViewController?

I read in many questions that I need to call:

[self.tabBarController dismissViewControllerAnimated:NO completion:nil];

However - where do I call it from? I tried from MyViewController - but since it's not part of the UITabBar, self.tabBarController is null.

I initialize the UiTabBarController from storyboard and not from appDelegate and I would like to leave it that way.

nhgrif
  • 58,130
  • 23
  • 123
  • 163
Dejell
  • 12,840
  • 37
  • 129
  • 217

1 Answers1

6

Use the presented viewController's presentingViewController property

Objective-C

[self.presentingViewController  dismissViewControllerAnimated:NO completion:nil];

Swift

presentingViewController?.dismissViewControllerAnimated(false, completion: nil)

You can also use this shorthand version (I don't recommend you do, but you will see it often)

Objective-C

[self dismissViewControllerAnimated:NO completion:nil];

Swift

dismissViewControllerAnimated(false, completion: nil)

see
Dismissing a Presented View Controller

Community
  • 1
  • 1
foundry
  • 30,849
  • 8
  • 87
  • 124