ios Xcode 选项卡式应用程序 - 添加新选项卡视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7952576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:07:48  来源:igfitidea点击:

Xcode Tabbed Application - Adding New Tab view

iosiphonexcodestoryboarduitabbaritem

提问by Gayan

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.

我正在使用 Xcode 4.2。我开始使用标签式应用程序,现在我想在我的应用程序的故事板上添加第 3 个和第 4 个标签式应用程序。我怎样才能添加它?我尝试使用它,但我不能。:( 我没有得到好的教程。

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.

我浏览了此链接,但我需要在第一个视图中添加另外 2 个选项卡式视图。

Update:

更新:

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

只需创建选项卡式应用程序,他们就会尝试添加一两个选项卡视图。我还在尝试。但我不能。

回答by 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.

只需在您的项目中再添加两个视图控制器,然后控制从选项卡栏控制器到视图控制器的拖动以对它们进行转场。确保在弹出列表时选择“Relationship-viewControllers”。标签将自动添加。

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.

您必须转到菜单并单击“新建文件”,然后单击 Objective-C 类,最后确保选择 UIViewController 子类。命名它,然后它会添加 .h 和 .m 文件。现在在您的故事板中,确保将每个选项卡的类更改为您的文件名。就是这样。

回答by Suragch

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.

按住 Control 从 Tab View Controller 拖动到新的 View Controller 以获取菜单。

enter image description here

在此处输入图片说明

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

就是这样。观看以下视频了解更多详情。

回答by Rutvij Kotecha

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

我使用的是 Xcode 4.3.3,并且可以通过以下步骤添加其他选项卡:

  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.
  1. 创建选项卡式应用程序。
  2. 确保实用程序已打开。从 Objects 中选择 View Controller 并拖放到 *.storyboard 中。
  3. 单击并按住控制键。单击 Tab Controller 并将光标移动到您添加的新视图控制器。当您松开鼠标按钮和控制键时,您将看到一个弹出窗口,其中包含 4 个选项: - 关系 - 视图控制器、推送、模态和自定义。
  4. 如果您选择关系 - 视图控制器选项,Xcode 会自动添加另一个选项卡并将选项卡控制器连接到您添加的窗口。

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

从这一点开始,修改选项卡的文本/图片非常简单。

回答by Kyle Clegg

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

以编程方式将第三个视图控制器添加到标准选项卡式 iOS 应用程序:

  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.

  1. 转到File -> New -> File,选择Objective-C类,为类输入“ThirdViewController”,在选项的子类下选择“UIViewController”。选中“使用 XIB 用于用户界面”。

  2. 转到新的 XIB 并添加标签或您选择的其他对象。

  3. 在 AppDelegate.m 中,通过添加#import "ThirdViewController.h"到文件导入来导入您的新类。

  4. 仍然在AppDelegate.m,在didFinishLaunchingWithOptions方法产生用于第三视图一个UIViewController对象(按照前两个的格式),和第三视图控制器添加到下面的tabbarcontroller两行: self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];

  5. 保存并运行您的项目。

The didFinishLaunchingWithOptions method should look like this when finished:

完成后 didFinishLaunchingWithOptions 方法应如下所示:

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

回答by Steve Ives

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.

不是你问的,但是当创建一个新的应用程序时,你可以创建你想要从 Tab Bar Controller 访问的所有视图控制器,然后选择它们并从“编辑器”菜单。

回答by William Cerniuk

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.

然后,您可以复制和粘贴,不仅在 StoryBoard 中生成一个新的 ViewContoller,而且捕获您可能为原始 ViewController 费力设置的所有自动布局。这是我所知道的捕获自动布局设置的唯一方法。

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.

最终,您可以通过这种方式创建一些 StoryBoard 模板,并将它们放在磁盘上。例如,我有一个“登录条目”ViewController,我以这种方式复制并粘贴它以用于我的应用程序。

And for the new folks, InterfaceBuilder breaks many of the object drawing app paradigms and is inconsistent within itself. Objects insidea 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.

而对于新手来说,InterfaceBuilder 打破了许多对象绘制应用程序的范式,并且本身就不一致。可以按预期单击视图控制器的对象并吸毒;按预期具有用于调整大小等的多边形句柄。ViewControllers 不响应 click-n-drag。相反,您必须在该标题上单击并拖动以拖动它。

回答by Play cool

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.

我的理解,据此我给出一个答案。应该有“标签栏控制器”当你提取这个“标签栏控制器”时,你会发现导航控制器。只需将这个和过去复制到那个标签栏控制器中。