1

如果我想在运行时通过另一个文件名 MainWindow2.xib 更改它,我已经在 .plist 文件中添加了我的 MainWindow.xib 文件名。我们如何通过代码更改它?

4

1 回答 1

1

你不能,因为info.plist应用程序包是只读的。您将不得不通过代码来完成。

从 info.plist 中删除所有主窗口,这是一个示例:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UIViewController *rootViewController = nil; 
    // Override point for customization after application launch.
    if (YES) { //You check here
        rootViewController = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil];
    } else {
        rootViewController = [[OtherViewContoller alloc] initWithNibName:@"OtherViewContoller" bundle:nil];
    }
    self.window.rootViewController = rootViewController;        
    [self.window makeKeyAndVisible];

    return YES;
}

中的main.m

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}
于 2012-06-22T12:49:11.397 回答