Is a MainWindow.xib truly needed in iOS application?

后端 未结 3 1900
旧时难觅i
旧时难觅i 2020-12-08 12:10

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.

相关标签:
3条回答
  • 2020-12-08 12:52

    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.

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

    0 讨论(0)
  • 2020-12-08 13:01

    I always feel confused about the usage of MainWindow.xib: even with it I still need to set window's rootViewController or addSubview to it. Isn't that information contained in MainWindow.xib ? Why I still need to tell window about that?

    So removing MainWindow.xib seems to make sense.

    0 讨论(0)
  • 2020-12-08 13:03

    It is has always been an option not to use MainWindow.xib. The UIWindow could be loaded programmatically by the doing the following:

    1) Making sure that the call to UIApplicationMain in main.m looks like this:

    UIApplicationMain(argc, argv, nil, @"MyAppDelegateClassName");
    

    rather than this:

    UIApplicationMain(argc, argv, nil, nil);
    

    2) Making sure that Info.plist does not have a value of "MainWindow.xib" as the main nib file.

    3) Loading the UIWindow programmatically in the app delegate.

    So, no, you don't have to use MainWindow.xib and, actually, you never have. You could always do things programmatically.

    It is a good question why Apple made this change in the default Xcode settings, and I don't know the answer. But it may have to with performance or the transition to ARC or small application file sizes or something else altogether.

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