Xcode Tabbed Application - Adding New Tab view

60,371

Solution 1

Just add two more view controllers to your project, and then control drag from the tab bar controller to the view controllers to make segues to them. Make sure you select "Relationship-viewControllers" when the list pops up. Tabs will automatically be added.

You have to go to the menu and click on "New File", then Objective-C class, and finally make sure to select UIViewController subclass. Name it and then it will add the .h and .m files. Now in your storyboard make sure to change the class of each tab to the name of your file. That's it.

Solution 2

For those who are visual learners:

Create a new Tabbed Application project

enter image description here

Which will give you a storyboard like this:

enter image description here

Add new View Controller

enter image description here

Add Tab Bar Item

enter image description here

Connect to Tab View Controller

Control-drag from the Tab View Controller to the new View Controller to get the menu.

enter image description here

That's it. Watch the following video for more details.

Solution 3

I am using Xcode 4.3.3 and I was able to add additional tabs by the following steps:

  1. Create a Tabbed Applications.
  2. Make sure Utilities is open. Pick View Controller from the Objects and drag and drop in *.storyboard.
  3. Click and hold control key. Click on Tab Controller and move the cursor to the new View Controller that you have added. When you release the mouse button and control key, you will see a popover which reads 4 options: - Relationship - View Controller, Push, Modal and Custom.
  4. If you select Relationship - View Controller option, Xcode automatically adds another tab and connects the Tab Controller to the window that you added.

From this point onwards it is pretty simple to modify the text/pictures of the tab.

Solution 4

To programatically add a third view controller to a standard tabbed iOS application:

  1. Go to File -> New -> File, select Objective-C class, enter "ThirdViewController" for the class, select "UIViewController" under the subclass of option. Check "With XIB for user interface."

  2. Go to the new XIB and add a label or other objects of your choice.

  3. In AppDelegate.m import your new class by adding #import "ThirdViewController.h" to the file imports.

  4. Still in AppDelegate.m, in the didFinishLaunchingWithOptions method create a UIViewController object for the third view (follow the format for the first two), and add the third view controller to the tabbarcontroller two lines below: self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];.

  5. Save and run your project.

The didFinishLaunchingWithOptions method should look like this when finished:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

Solution 5

Not what you asked, but when creating a new application, you can create all of the view controllers that you will want to access from a Tab Bar Controller, then select them all and select 'Embed in...Tab Bar Controller' from the 'Editor' menu.

Share:
60,371

Related videos on Youtube

Gayan
Author by

Gayan

Updated on March 21, 2020

Comments

  • Gayan
    Gayan about 4 years

    I'm working with Xcode 4.2. I started to work with Tabbed Application and now I want to add 3rd and 4th Tabbed to story board on my application. How Can I add it? I try to use it but I cannot. :( I didn't get good tutorials for it.

    Does anyone have any idea how to do this?

    I went through this link, but I need to add 2 more Tabbed views to first view.

    Update:

    Just go and create Tabbed Application and they try to add one or two more tab view. I'm still trying it. But I can't.

  • Steve Ives
    Steve Ives over 11 years
    Clarification: quickly draw 8, 9, 10 etc View Controllers, drag your mouse around the whole lot and then use the 'Embed in ...Tab Bar Controller' : voila - one new TBC with however many controllers all set and ready to go without having to idividually CTRL-Drag to each one.
  • itsazzad
    itsazzad over 11 years
    its old style. discouraged in the latest Xcode which supports storyboard features.
  • Kyle Clegg
    Kyle Clegg over 11 years
    I wouldn't say it's discouraged (definitely not deprecated by any means), but yes you can do it all via the storyboard as well using Jamie's answer.
  • itsazzad
    itsazzad over 11 years
    see the question description: "I want to add 3rd and 4th Tabbed to story board on my application". So according to the question your answer is not well
  • Kyle Clegg
    Kyle Clegg over 11 years
    Yes, but perhaps someone will get frustrated with storyboards for one reason or another (a hem) and look for another solution. Doesn't hurt to pitch in an alternative solution here or there.
  • Kyle Clegg
    Kyle Clegg over 11 years
    Anyway, you're free to downvote it (as I'm sure you already did).
  • Vaibhav Saran
    Vaibhav Saran about 11 years
    bravo @Kyle, I agree with you solution too and the code is running well. But what If i dont want to create xib files in stroyboard application and want to use storyboard viewcontrollers only? Any solution?
  • Vaibhav Saran
    Vaibhav Saran about 11 years
    i think it is not possible, for dynamic UITabBar items i have to creat XIB app rather than storyboard :-(
  • d1jhoni1b
    d1jhoni1b almost 8 years
    "it was not working" for me then realized i was hitting "command" key instead of "CONTROL" key, BTW nicely done !! the link of the youtube video made me realize i was using "command" key, thumbs up.
  • Cerniuk
    Cerniuk about 6 years
    (err: human-code abort at line 1) If you add a view controller, aka ThirdViewController.m, to the "project" and control drag to that view controller (aka file), nothing happens... I think you mean "add more view controllers to the Storyboard" and not "project" ;-)