Search code examples
iphonecocoa-touchios4

After dismissModalViewControllerAnimated: my tabbar disappears


I have an app which consists of three layers of view controllers: UITabBarController => UINavigationController => UIViewController. They are all generated in code rather than using IB. The tab bar is on the bottom as per the usual design guidelines. In my UIViewController I am using this code to present the modalViewController:

myModalVC = [[MyModalViewController alloc] init];
[self.navigationController presentModalViewController:myModalVC animated:YES];

This work fine and the modal view controller pops up and covers the entire screen.

However when a button is pressed within the modal view controller, I run this:

[self dismissModalViewControllerAnimated:YES];

And the modal view controller animates away. However I can see the original UIViewcontroller view but the tab bar disappears completely. I've googled a lot but I can't find anyone that has this same problem.


Solution

  • Actually I found this by googling a bit more. I made my tab bar controller a property of the app delegate and when it presents the modal vc, it does this

    UIApplication *myApp = [UIApplication sharedApplication];
    noIBAppDelegate*appDelegate = (noIBAppDelegate*)myApp.delegate;
    [appDelegate.tabBarController presentModalViewController:myModalVC animated:YES];
    

    Then it dismisses it by this bit of code

    UIApplication *myApp = [UIApplication sharedApplication];
    noIBAppDelegate*appDelegate = (noIBAppDelegate*)myApp.delegate;
    [appDelegate.tabBarController dismissModalViewControllerAnimated:YES];
    

    This fixes the the tab bar disappearing.