how to structure my objects when using uinavconttroller and uitabbar
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.h
add a property@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
In your
AppDelegate.m
firstly 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.xib
drag aTab Bar Controller
object onto your objects area (this is where yourAppDelegate
andWindow
objects are).- Ctrl + Drag from the
AppDelegate
to theTab Bar Controller
object 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
UIViewController
then just change the classes of these objects to represent yourUIViewController
sub classes.
- If you want to use
UINavigationController
then drag aUINavigationController
object onto yourTab Bar Controller
object.
- Now click the disclosure triangle on
UINavigationController
and change the class of itsViewController
to be your custom subclass ofUIViewController
.
精彩评论