Xcode Tabbed Application - Adding New Tab view

前端 未结 7 530
南笙
南笙 2020-12-04 20:01

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

相关标签:
7条回答
  • 2020-12-04 20:17

    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.

    • Tab bar for Xcode Swift for iOS
    0 讨论(0)
  • 2020-12-04 20:22

    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.

    0 讨论(0)
  • 2020-12-04 20:22

    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.

    0 讨论(0)
  • 2020-12-04 20:24

    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;
    }
    
    0 讨论(0)
  • 2020-12-04 20:34

    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.

    0 讨论(0)
  • 2020-12-04 20:40

    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.

    0 讨论(0)
提交回复
热议问题