Xcode Tabbed Application - Adding New Tab view

不想你离开。 提交于 2019-11-27 18:47:17
Jamie

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.

For those who are visual learners:

Create a new Tabbed Application project

Which will give you a storyboard like this:

Add new View Controller

Add Tab Bar Item

Connect to Tab View Controller

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

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

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.

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;
}

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.

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!