need example of tabbar with navbar

Discussion in 'iOS Programming' started by beachdog, Aug 27, 2008.

  1. beachdog macrumors member

    Aug 10, 2008
    I have worked my way through building an app with a navbar, and now have a pretty good understanding of that. And I created an application template for a tabbar application and kind of see how that works. But I need to build an app that has both a tab bar as well as nav bars. Is there a sample app that falls into that UI design which I could look at ?
  2. belsokar macrumors member

    Jul 21, 2005
    Create the TabBarView Controller in your main application delegate.

    Now Create your NavBarViewController. You need to add your NavBarViewController to the ViewControllers property of the TabBarViewController.

    You then add your TabBarViewController to your main window.

    PM me if you want to see some sample code.
  3. sujithkrishnan macrumors 6502

    May 9, 2008

    Adding to the question above can u please suggest me a method to redraw the tabBar at runtime ???

    means... can we change the items of tabBar as per user choice...

    I created the tabBar with navBar as you suggested above...

    Little bit of code is also much helpful....
  4. dwsouth2 macrumors newbie

    Sep 9, 2008
    Please share the code online

    I am having a problem with this also. Could you please post your example code or contact me. The light at the end of the tunnel is evading me.
  5. beachdog thread starter macrumors member

    Aug 10, 2008
    I did it mostly thru interface builder, which makes it difficult to show code, but here are the steps I did:

    First, I started by creating a basic tab-bar project, without navigation controllers. This created my main nib file, with the tabs along the bottom of my main window and the views associated with each above.

    Then, for the particular tabs where I wanted to show the associated view under a nav bar, I selected that tab button in Interface Builder, and in the inspector I then changed the Class Identity of the associated view for that tab from UIViewController to UINavigationController. That seemed to be the main trick.

    I then selected the view itself (the view which appears under the nav controller, which in my case is a UITableView) and I changed its Class Identity from UITableViewController to my custom class which inherited from UITableViewController. I also specified that that view controller should be associated with a different nib file. That nib file simply had the table view that I wanted to show beneath the nav bar, with File's Owner being my custom UITableViewController-derived class.

    The upshot is that when the user clicks that tab bar it creates a navigation controller. The navigation controller in turn then creates an instance of my custom UITableViewController-derived class and loads the second nib file containing that view. My custom class then accesses the navigation bar by means of code like this:

    - (void)viewDidLoad {
      [super viewDidLoad];
       /* I wanted a segmented control to appear in the nav bar */
       UISegmentedControl* ctl = [[UISegmentedControl alloc] initWithItems:[NSArray 
       ctl.segmentedControlStyle = UISegmentedControlStyleBar;
       [ctl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
       ctl.selectedSegmentIndex = 0;
       self.navigationItem.titleView = ctl ;
       /* set the nav bar title */
       self.title = NSLocalizedString(@"food_list","");
  6. siva.d macrumors newbie

    Sep 30, 2008
    i also need same kind of application


    I need same kind of application.

    I have some doubts, how u connected in nib files.

    Can you give sample code of the application you created.

    By seeing those nib files, i will try to understand.

  7. matthew858 macrumors member

    Apr 15, 2008
    Sydney, Australia
    I would also love a .xcodeproj file that somebody is willing to share. I am not quite sure how to do this, as my app keeps crashing.
  8. siva.d macrumors newbie

    Sep 30, 2008

Share This Page