TabBar controller +Navigationa Controller

Discussion in 'iOS Development' started by deepp, Mar 23, 2009.

  1. deepp

    deepp New Member

    Joined:
    Sep 4, 2008
    Messages:
    73
    Likes Received:
    0
    Hi everyone ,I want to know how i can embed Tab bar into Navigationcontroller project?what i am trying to do is that i am trying to add it in rootviewcontroller but as i need to have table view in rootview so this also not working when i add tab Bar controller ,tableview gets vanished...
    I am trying to do it but i guess i am lacking any point...
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    I'll be brief because this is not different than any other type of view controller.

    Code:
    /* Create the navigation controller and set its root controller to your table controller  */
    
    	 UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:[[YourTableController alloc] initWithStyle:UITableViewStylePlain]];
    	[window addSubview:[navController view]];
    
    /* Set up the Tab Bar Controller  */
    
    	 UITabBarController *yourTabController = [[UITabBarController alloc] init];
    	 [yourTabController setViewControllers:[NSArray arrayWithObjects:yourFirstViewController, yourSecondViewController, yourthirdViewController, yourFourthViewController, nil] animated:NO];
    	 yourTabController.delegate = whatever;
    
    /* Later, when it's time to push to the tab bar controller */
    	[self.navigationController pushViewController:yourTabController animated:YES];
    Alternatively, do this in IB. It's just as easy
  3. deepp

    deepp New Member

    Joined:
    Sep 4, 2008
    Messages:
    73
    Likes Received:
    0
    Thanks Skylar but how can i do this using IB as my project template is Navigation based so when do that in IB my Table View gets removed so could not add using IB. Now i am trying to do what you said .but i am bit confused with your code.The variable youtablecontroller i did not understand this.Please help.
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Here this is base on the UINavigationController based project template.
    http://www.touchrepo.com/SampleCode/NavToTab.zip

    I would have posted this much earlier, but I had the tab bar created with separate xibs itself.
    I decided at the last minute to simplify everything and put it all in the same xib, the
    RootViewController xib, so as for easy following along.

    As you can see, you literally do this exactly the same way you push to any other view
    controller. Don't forget that a UITabBarController is a subclassed UIViewController.
  5. deepp

    deepp New Member

    Joined:
    Sep 4, 2008
    Messages:
    73
    Likes Received:
    0
    Thanks thanks thanks thanks a lot Skylar.......

    Please Register or Log in to view images


    but would you kill me if i say that i wanted to display Tab bar and Navigation bar on launch of application itself....

    Please Register or Log in to view images

    anyways the code which you have given is really really useful i'll use and try myself to display nav bar and tab bar on first page itself thanks a lot for your help.....
  6. ZunePod

    ZunePod Banned

    Joined:
    Aug 28, 2008
    Messages:
    1,340
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    Sorry to dig this up, but something is broken in 3.0 in this section:

    Code:
    	 UITabBarController *yourTabController = [[UITabBarController alloc] init];
    	 [yourTabController setViewControllers:[NSArray arrayWithObjects:yourFirstViewController, yourSecondViewController, yourthirdViewController, yourFourthViewController, nil] animated:NO];
    	 yourTabController.delegate = whatever;
    
    I've changed the Object names and stuff but something is broken just before you name your controllers.
  7. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    It look like UINavigationController is not pushing UITabBarController so it show up like a blank page with navigationController without tab bar.

    Found it - [navController pushViewController:yourTabController animated:YES];

Share This Page