开发者

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 des开发者_JS百科ign 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.


You should delegate your modal view controller to your parent view controller. [self dismissModalViewControllerAnimated:YES]; should be done by the delegate and not the modal view itself, parent view are responsible for dismissing the modal view.


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.


Try

[self.navigationController dismissModalViewControllerAnimated:YES];


Thanks for your answer! I had the same problem, but I'm writing in Swift, so thought I'd include my solution that I figured out from looking at yours. I only had to use these two lines to fix the problem. Nothing else was needed.

tabBarController?.presentViewController(viewController, animated: true, completion: nil)

and

tabBarController?.dismissViewControllerAnimated(true, completion: nil)

I should also mention that the line: tabBarController?.delegate = self, is in the viewDidLoad function of my NavigationController.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜