26

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.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Gayan
  • 1,425
  • 4
  • 21
  • 41

7 Answers7

60

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.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Jamie
  • 5,090
  • 28
  • 26
  • (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" ;-) – Cerniuk Mar 20 '18 at 12:26
34

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.

Community
  • 1
  • 1
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • 1
    "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. – d1jhoni1b Aug 02 '16 at 01:41
8

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.

Rutvij Kotecha
  • 935
  • 2
  • 10
  • 21
6

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;
}
Kyle Clegg
  • 38,547
  • 26
  • 130
  • 141
  • its old style. discouraged in the latest Xcode which supports storyboard features. – itsazzad Nov 25 '12 at 05:54
  • 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. – Kyle Clegg Nov 25 '12 at 10:01
  • 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 – itsazzad Nov 25 '12 at 13:15
  • 2
    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 Nov 26 '12 at 05:49
  • 1
    Anyway, you're free to downvote it (as I'm sure you already did). – Kyle Clegg Nov 26 '12 at 05:50
  • 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 Mar 18 '13 at 06:41
  • i think it is not possible, for dynamic UITabBar items i have to creat XIB app rather than storyboard :-( – Vaibhav Saran Mar 18 '13 at 06:51
2

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.

Steve Ives
  • 7,894
  • 3
  • 24
  • 55
  • 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. – Steve Ives Oct 02 '12 at 11:08
1

If you click on the small header bar where you see the three icons:

enter image description here

You can then copy and paste to not only generate a new ViewContoller in the StoryBoard, but capture all of the auto-layout you may have laboriously setup for that original ViewController. This is the ONLY way to capture the auto-layout settings that I know of.

Ultimately you can create some StoryBoard templates this way and have them just sitting around on disk. I have a "login entry" ViewController that I copy and paste this way for my apps for example.

And for the new folks, InterfaceBuilder breaks many of the object drawing app paradigms and is inconsistent within itself. Objects inside a view controller can be clicked and drug as expected; have polygon handles for resizing, etc as expected. ViewControllers do not respond to a click-n-drag. Instead you must click-n-drag on that header thing to drag it.

Cerniuk
  • 14,220
  • 2
  • 29
  • 27
0

What i understand , according to this i give a answer. There should be "Tab bar controller" When u extract this "tab bar controller" u will find Navigation controller. Just copy this and past into that Tab bar controller.

Play cool
  • 158
  • 4
  • 12