I am trying to understand what is a proper structure of the objects when using uinavigationcontroller with a tab bar.
I want my app to have the following structure: welcome/login screen -> 3 bar tabs.
I have the following objects/classes:
- AppDelegate
- WelcomeViewController
- TabController
- FirstTab
- SecondTab
- ThirdTab
I have also created a uinavcontroller under WelcomeViewController once the user clicks on "enter" to the app:
-(IBAction)aMethod:(id)sender {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FirstView *controller = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
self.window.rootViewController = self.navigationController;
navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navigationController animated:YES];
}
My question is - how should I manage the tab bar - where should I declare each one of its pieces, and will I need to create a uitabbarcontroller in this case (in which case, where?)).
I am very co开发者_JAVA百科nfused as to how to place the different tab bar related declarations and none of the examples/ tutorials our there were able to clarify this for me.
BTW - I started this app from a view based application.
Thanks!
You can either set this up in code or you can do it using interface builder.
I prefer the interface builder method as you can visually see the structure of your view controllers.
This is how I do it...
In your
AppDelegate.hadd a property@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;In your
AppDelegate.mfirstly synthesize the property@synthesize tabBarController = _tabBarController;Set up the
application:didFinishLaunchingWithOptions:method to look something like this (you may do more work in this method)- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self.window addSubview:self.tabBarController.view]; [self.window makeKeyAndVisible]; return YES; }In
MainWindow.xibdrag aTab Bar Controllerobject onto your objects area (this is where yourAppDelegateandWindowobjects are).
- Ctrl + Drag from the
AppDelegateto theTab Bar Controllerobject and select the property that we just made.
NOTE: Now we have a Tab Bar Controller set up and ready to roll.
- There should be two tabs set up as an example. If you just want to use sub classes of
UIViewControllerthen just change the classes of these objects to represent yourUIViewControllersub classes.

- If you want to use
UINavigationControllerthen drag aUINavigationControllerobject onto yourTab Bar Controllerobject.

- Now click the disclosure triangle on
UINavigationControllerand change the class of itsViewControllerto be your custom subclass ofUIViewController.
加载中,请稍侯......
精彩评论