How to put tab bar controllers inside of view controllers and not the delegate?
I have a very basic iphone app where the following steps occur.
- App Delegate which loads...
- Game root view controller (this is just 2 b开发者_运维百科uttons, "start game" and "continue game")
- When the start game button is clicked load RootViewController.
- Root View Controller with a tab bar controller??
I'm really not sure how games do this in iPhone apps but the above is my best guess.
I want the tab bar controller only to appear inside the RootViewController, but regardless of what I do I cannot make the tab bar controller appear inside this view.
I can however make normal tab bars appear. But this is not a tab bar controller, I need control over what each of these tabs do (navigation controller, table controller, etc).
According to the docs one of the many ways of using a tab bar controller is via the application’s main window. But it doesn't say whether you can use it in a normal view; or indeed how.
I tried several attempts to make the tab bar controller appear to no avail.
For example, in my GameRootViewController inside the button if I do this;
-(IBAction) btnPress {
RootViewController *root = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
[self.view addSubview:root.tabBarController.view];
[root release];
}
Nothing appears.
If I try the normal way of doing:
[self.view addSubview:root.view];
The view appears but I never see the tab bar controller.
This makes me very confused.
I'm thinking possibly that games/apps could do this:
- App Delegate
- Load all the splash screens, credits, made by...etc
- Load the start game, continue game screen and handle the actions these create
- Make the app delegate window add the tab bar controller to the self.window.
But I am not sure. I want to clarify/understand whether I can put tab bar controllers inside of view controllers, or can they only ever be used inside the app delegate?
Firstly, don't confuse controllers with views. Views are visible parts of the UI, controllers are invisible objects behind the scenes. You don't put controllers inside of views or controllers "inside" other controllers. Instead, controllers exist in various hierarchies and the structure of those hierarchies dictates which views appear when and where.
You are using a tabbar in a none standard way (which may confuse users) but you need put the tabbar controller inside of a navigation controller so that you get an hierarchy that looks like:
navigationController (rootViewController)
-->TabBarController(secondController)
-->tabViewController1
-->tabViewController2
-->tabViewController3
So, you first visible view is the button view which is controlled by the rootController of the navigationController. Upon selecting a button, it pushes the TabViewController onto the nav stack which brings the tabbar into view with it's default tab selected. (Note you will have to hide the navigation bar to make the navigation stack invisible to the user.)
精彩评论