如何在运行时更改位于.plist中的属性,称为“主nib文件基本名称”

时间:2012-06-22 12:45:07

标签: iphone

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

1 个答案:

答案 0 :(得分: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]));
    }
}