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

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

问题描述

在使用Xcode 4.2进行任何类型的iOS 5.0开发之前,Xcode在模板中提供了MainWindow.xib。下载并使用iOS 5.0使用Xcode 4.2后,我注意到所提供的模板都不包含任何MainWindow.xib文件。我们还需要这个吗?我注意到在App_Delegate的application 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天全站免登陆