我已经在.plist文件中添加了我的MainWindow.xib文件名,如果我想在运行时通过另一个文件名MainWindow2.xib更改它。我们如何通过代码更改它?
答案 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]));
}
}