iOS 应用程序真的需要 MainWindow.xib 吗? [英] Is a MainWindow.xib truly needed in iOS application?

查看:22
本文介绍了iOS 应用程序真的需要 MainWindow.xib 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Xcode 4.2 进行任何类型的 iOS 5.0 开发之前,Xcode 在模板中提供了MainWindow.xib".在 iOS 5.0 下载并使用 Xcode 4.2 后,我注意到提供的模板都不包含任何MainWindow.xib"文件.我们还需要这个吗?我注意到在 App_Delegate 中的应用程序 didFinishLaunchingWithOptions"方法中,模板现在包含创建一些UIWindow"的代码,如果您有任何导航控制器,它会相应地更新窗口.

Before doing any type of iOS 5.0 development using Xcode 4.2, Xcode has provided a "MainWindow.xib" in templates. After downloading and playing with Xcode 4.2 with iOS 5.0, I noticed that none of the templates provided include any "MainWindow.xib" files. Do we need this anymore? I noticed that in the "application didFinishLaunchingWithOptions" method in the App_Delegate that the templates now include code that creates some "UIWindow" and if you have any navigation controllers, it updates the window accordingly.

// code that was pulled from a Master Detail application template
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

我想我的问题是,我还需要MainWindow.xib"吗?如果需要,那么为什么 Apple 模板会排除它们?

I guess my question is, do I need a "MainWindow.xib" any longer, and if so, then why do the Apple templates exclude them?

推荐答案

我认为它现在不存在的原因是,以编程方式创建窗口比打开 xib 文件并取消归档对象更有效.一般来说,如果你可以在一行代码中做到,你应该在代码中做到这一点.

I think the reason why it's now absent is that creating a window programmatically is much more efficient than opening a xib file and unarchiving the objects. Generally, if you can do it in one line of code, you should do that in code.

阅读 Matthew Gillingham 的回答,了解如何手动更改旧项目以使其在没有 MainWindow.xib 的情况下工作.

Read Matthew Gillingham's answer for instructions on how to manually change an old project to work without the MainWindow.xib.

这篇关于iOS 应用程序真的需要 MainWindow.xib 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆