need example of tabbar with navbar

Discussion in 'iPhone/iPad Programming' started by beachdog, Aug 27, 2008.

  1. macrumors member

    Joined:
    Aug 10, 2008
    #1
    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. macrumors member

    Joined:
    Jul 21, 2005
    #2
    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. macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #3
    Hi...

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

    Joined:
    Sep 9, 2008
    #4
    Please share the code online

    Hi,
    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.
    Thanks
    Tony
     
  5. thread starter macrumors member

    Joined:
    Aug 10, 2008
    #5
    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:

    Code:
    - (void)viewDidLoad {
      [super viewDidLoad];
    	
       /* I wanted a segmented control to appear in the nav bar */
       UISegmentedControl* ctl = [[UISegmentedControl alloc] initWithItems:[NSArray 
               arrayWithObjects:NSLocalizedString(@"all",@""),NSLocalizedString(@"restaurants",@""),NSLocalizedString(@"favorites",@""),nil]];
       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. macrumors newbie

    Joined:
    Sep 30, 2008
    Location:
    Hyderabad,India
    #6
    i also need same kind of application

    Hi,

    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.

    Thanks
    shiva
     
  7. macrumors member

    Joined:
    Apr 15, 2008
    Location:
    Sydney, Australia
    #7
    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. macrumors newbie

    Joined:
    Sep 30, 2008
    Location:
    Hyderabad,India
    #8

Share This Page