Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
901 views
in Technique[技术] by (71.8m points)

xcode - Is a MainWindow.xib truly needed in iOS application?

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...