Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Adding Tab Bar Controller in Interface Builder

nonfictionnonfiction Posts: 6New Users
edited December 2010 in iOS SDK Development
I created a new UIViewController with "XIB for user interface" and want to implement a Tab Bar Controller using Interface Builder.

Opening up the XIB I originally have: File's Owner, First Responder, and View. I added a Tab Bar Controller, but when I build and simulate the project only the View shows. How do I get The Tab Bar Controller to appear?
Post edited by nonfiction on

Replies

  • aldcorn@live.comaldcorn@live.com Posts: 554Registered Users
    edited December 2010
    Hi,
    You need to have the tabbar controller higher up in your hierarchy. The views will be subviews of the tabbar not the other way around.
    Hope this helps,
    Rob
    nonfiction wrote: »
    I created a new UIViewController with "XIB for user interface" and want to implement a Tab Bar Controller using Interface Builder.

    Opening up the XIB I originally have: File's Owner, First Responder, and View. I added a Tab Bar Controller, but when I build and simulate the project only the View shows. How do I get The Tab Bar Controller to appear?
  • nonfictionnonfiction Posts: 6New Users
    edited December 2010
    Hi,
    You need to have the tabbar controller higher up in your hierarchy. The views will be subviews of the tabbar not the other way around.
    Hope this helps,
    Rob



    Having the Tab Bar Controller higher up in my hierarchy didn't fix the problem. Initializing the UITabBarController in my ViewController Class and adding it as a subview in the viewDidLoad function works, however, the bottom of the Tab Bar Controller gets cut off at the bottom of the screen.
  • aldcorn@live.comaldcorn@live.com Posts: 554Registered Users
    edited December 2010
    If you shorten the views presented by your tabs the tabbar should show up properly. Are you using code or interface builder?
    nonfiction wrote: »
    Having the Tab Bar Controller higher up in my hierarchy didn't fix the problem. Initializing the UITabBarController in my ViewController Class and adding it as a subview in the viewDidLoad function works, however, the bottom of the Tab Bar Controller gets cut off at the bottom of the screen.
  • nonfictionnonfiction Posts: 6New Users
    edited December 2010
    If you shorten the views presented by your tabs the tabbar should show up properly. Are you using code or interface builder?



    I'm using Interface Builder for the view layouts. In my MainMenuViewController class I have code that gets invoked after pressing a button:
    MyTabViewController *screen = [[MyTabViewController alloc] initWithNibName:@"MyTabView" bundle:nil];
    		screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    		[self presentModalViewController:screen animated:YES];
    		[screen release];
    
    //MyTabViewController.h
    
    @interface MyTabViewController : UIViewController {
    
    	IBOutlet UITabBarController *tabBarController;
    }
    
    @property(nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    
    @end
    
    //MyTabViewController.m
    
    @implementation MyTabViewController
    
    @synthesize tabBarController;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    	
    	[self.view addSubview:tabBarController.view];
    }
    
    


    I tried shortening the length of the views for the tab view items, but the tab bar is still getting cut off.
  • aldcorn@live.comaldcorn@live.com Posts: 554Registered Users
    edited December 2010
    Try to resize your tabBarController view or change it's origin in interface builder. If it doesn't change make sure it is hooked up to the iboutlet in ib.
    MyTabView in your initWithNibName is not the same as MyTabViewController
  • nonfictionnonfiction Posts: 6New Users
    edited December 2010
    Try to resize your tabBarController view or change it's origin in interface builder. If it doesn't change make sure it is hooked up to the iboutlet in ib.
    MyTabView in your initWithNibName is not the same as MyTabViewController



    I can't resize the UITabBarController. It says "Not Applicable" in the Inspector. The Tab Bar Controller has a referencing outlet to File's Owner.

    As far as I know, the XIB (MyTabView.xib) doesn't need to be the same name as its controller class (MyTabViewController).

    UPDATE: I figured out the problem. In the MyTabBarViewController.m file instead of having:
    [self.view addSubview:tabBarController.view];
    

    I changed it to:
    self.view = tabBarController.view
    

    and now the bottom tab bar text shows up.
  • aldcorn@live.comaldcorn@live.com Posts: 554Registered Users
    edited December 2010
    When you were trying to add the tabbarcontroller as a subview you were trying to place it lower in the hierarchy.
    nonfiction wrote: »

    UPDATE: I figured out the problem. In the MyTabBarViewController.m file instead of having:
    [self.view addSubview:tabBarController.view];
    

    I changed it to:
    self.view = tabBarController.view
    

    and now the bottom tab bar text shows up.
Sign In or Register to comment.