开发者

how to structure my objects when using uinavconttroller and uitabbar

开发者 https://www.devze.com 2023-03-21 17:26 出处:网络
I am trying to understand what is a proper structure of the objects when using uinavigationcontroller with a tab bar.

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...

  1. In your AppDelegate.h add a property

    @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    
  2. In your AppDelegate.m firstly synthesize the property

    @synthesize tabBarController  = _tabBarController;
    
  3. 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;
    }
    
  4. In MainWindow.xib drag a Tab Bar Controller object onto your objects area (this is where your AppDelegate and Window objects are).

    how to structure my objects when using uinavconttroller and uitabbar

  5. Ctrl + Drag from the AppDelegate to the Tab Bar Controller object and select the property that we just made.

    how to structure my objects when using uinavconttroller and uitabbar

NOTE: Now we have a Tab Bar Controller set up and ready to roll.

  1. 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 your UIViewController sub classes.

how to structure my objects when using uinavconttroller and uitabbar

  1. If you want to use UINavigationController then drag a UINavigationController object onto your Tab Bar Controller object.

how to structure my objects when using uinavconttroller and uitabbar

  1. Now click the disclosure triangle on UINavigationController and change the class of its ViewController to be your custom subclass of UIViewController.

    how to structure my objects when using uinavconttroller and uitabbar

0

精彩评论

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