简体   繁体   中英

Segue to Tab Bar Controller

I have this problem:

I have an app that has 2 parts, the first part is when it's the first time the user opens the app, a screen with "whats your name" appears and he follows to a screen that has some buttons and it ends in a tableview where he can press a button in the footer to go to the other part of the app that is a view controller with 2 buttons: 1 - Go back to that first button screen (after whats your name), 2 - Go to tab bar controller. My problem is: when I segue to the tab bar controller 2 navigation bar's appear oO. I've read through the internet that I can't push a tab bar controller into a navigation stack, is that true?

So what is the solution for my UI? Since I want the user to be able to go back to that test screen, but I want to use this tab bar controller as well.

Thanks in advance!

I've read through the internet that I can't push a tab bar controller into a navigation stack, is that true?

Yes, it's true.

Take a look at the documentation for -[UINavigationController pushViewController:animated:] , which says this about the view controller it takes as a parameter:

This object cannot be an instance of tab bar controller and it must not already be on the navigation stack.

(Emphasis added.)

So what is the solution for my UI?

Organize your application differently. One way would be to make the tab controller your root controller and present the initial view controller modally when the app first starts. If the user needs to get back there, provide a button or some other means that displays the initial view controller modally again. Or just make that initial screen another tab, so that the user can get back to it at any time.

I'm using this to push a Tab Controller on top of a navigation controller. Just give you Tab Controller or Navigation Controller an identifier on the attributes inspector.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tab=[storyboard  instantiateViewControllerWithIdentifier:@"tabController"];
[self.navigationController presentViewController:tab animated:YES completion:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM