在 XCode 4.2 Empty Application 模板中使用 Interface Builder 将 tabbarcontroller 添加到 AppDelegate 的步骤

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8201207/
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-09-14 22:29:47  来源:igfitidea点击:

steps to add tabbarcontroller to AppDelegate using Interface Builder in XCode 4.2 Empty Application template

iphoneobjective-ciosxcodeios5

提问by JAHelia

while I'm stuck at this questionI cannot find the right steps to add a UITabBarController to the AppDelegate (not programatically) but by using interface builder for the "Empty Application" template, I tried to add a new empty xib file, then dropped uitabbarcontroller into it, but there is no way to link it (from IB) to AppDelegate !! i.e. when I move the blue line from tabbarcontroller object (in document outline) to File's Owner, interface builder shows only the "Delegate" option in the shown list so there is no IBOutlet option in there.

虽然我被困在这个问题上,但我找不到将 UITabBarController 添加到 AppDelegate 的正确步骤(不是以编程方式)但是通过使用“空应用程序”模板的界面构建器,我尝试添加一个新的空 xib 文件,然后删除uitabbarcontroller 到它,但没有办法将它(从 IB)链接到 AppDelegate !即,当我将蓝线从 tabbarcontroller 对象(在文档大纲中)移动到文件所有者时,界面构建器仅在显示的列表中显示“委托”选项,因此那里没有 IBOutlet 选项。

so, what are the exact steps for adding a tabbarcontroller and connect it to appDelegate using the interface builder way (for the Empty Application template, using XCode 4.2 and IOS 5 SDK) ?

那么,添加 tabbarcontroller 并使用界面构建器方式将其连接到 appDelegate 的确切步骤是什么(对于空应用程序模板,使用 XCode 4.2 和 IOS 5 SDK)?

step1: create new Empty Application template project.

step1:新建一个Empty Application模板项目。

... waiting for the next steps...

......等待下一步......

thanks so much in advance.

非常感谢。

回答by SEG

Step 1: create new Empty Application template project.
Step 2: add

步骤 1:创建新的 Empty Application 模板项目。
第 2 步:添加

@property (nonatomic, strong) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, strong) IBOutlet UIWindow *window;

in your app delegate. (dont forget to synthesize these) Step 3: change this line in your app delegate:

在您的应用程序委托中。(不要忘记合成这些)第 3 步:在您的应用程序委托中更改此行:

@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>

Step 4: modify this method

第四步:修改这个方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:[self.tabBarController view]];
[self.window makeKeyAndVisible];
return YES;
}  

Step 5: create a new empty xib. Drag a tab bar controller on to it as well as an empty object.
Set the empty object's class to AppDelegate. Set Files Owner to UIApplication.

第 5 步:创建一个新的空 xib。将一个标签栏控制器和一个空对象拖到它上面。
将空对象的类设置为 AppDelegate。将文件所有者设置为 UIApplication。

Step 6: drag the 'delegate' property from your files owner on to your appdelegate class and drag the tab bar outlet from you appdelegate class to your tabbarcontroller

第 6 步:将“delegate”属性从您的文件所有者拖到您的 appdelegate 类,并将标签栏出口从您的 appdelegate 类拖到您的 tabbarcontroller

Step 7: Add a window and drag the 'window' connection from your appdelegate to the window.

第 7 步:添加一个窗口并将“窗口”连接从您的 appdelegate 拖动到该窗口。

Step 8: Dont forget to go into the project settings and set the main-base nib file to the new xib you created.

第 8 步:不要忘记进入项目设置并将主库 nib 文件设置为您创建的新 xib。

Thats it. Hope I didn't miss anything.

就是这样。希望我没有错过任何东西。

回答by Bani Uppal

I don't understand what is the need to add a UITabBarController through the main window. With Xcode 4.2, Apple has made some changes in the default templates. It does not provide a MainWindow.xib in the Empty Application. That is why, if you open up the AppDelegate.h, you will see:

我不明白通过主窗口添加 UITabBarController 有什么需要。在 Xcode 4.2 中,Apple 对默认模板进行了一些更改。它在空应用程序中不提供 MainWindow.xib。这就是为什么,如果你打开 AppDelegate.h,你会看到:

@property (strong, nonatomic) UIWindow *window;

It does not have an IBOutlet for the window as we used to see in previous Xcode versions. What you want to achieve is a UITabBarController with Core Data support. You could add the tabBarController programatically, and still add CoreData support.

它没有我们在以前的 Xcode 版本中看到的窗口的 IBOutlet。您想要实现的是具有核心数据支持的 UITabBarController。您可以以编程方式添加 tabBarController,并且仍然添加 CoreData 支持。

回答by Tim Newton

Here's what I had to do.

这就是我必须做的。

From your storyboard's Objects list (Controllers & Objects) in the Utilities panel, drag over a generic "Object" (yellow cube) to your Tab Bar Controller Scene page (I place the object under the "Exit" object).

从“实用工具”面板中故事板的“对象”列表(控制器和对象),将通用“对象”(黄色立方体)拖到您的标签栏控制器场景页面(我将对象放在“退出”对象下)。

Set the class of the object to your appDelegate. Now you should be able to link your Tab Bar Controller's delegate to your appDelegate object. You can also link the appDelegate to the Tab Bar Controller if you've created a property such as

将对象的类设置为您的 appDelegate。现在您应该能够将 Tab Bar Controller 的委托链接到您的 appDelegate 对象。如果你已经创建了一个属性,你也可以将 appDelegate 链接到 Tab Bar Controller

@property (weak, nonatomic, readwrite) IBOutlet UITabBarController *tabs