gpt4 book ai didi

ios - Storyboard:在运行时设置初始 View Controller

转载 作者:行者123 更新时间:2023-11-28 21:54:07 24 4
gpt4 key购买 nike

我正在开发一个 iOS 7+ 应用程序,我被告知要根据我在运行时才知道的参数为应用程序设置不同的初始 View 。一个可能的初始 UIViewControllerUITabBarViewController,另一个是 UINavigationController

是否可以使用 storyboard 来管理它?或者它是使用单独的 nib 文件的唯一方法吗?

谢谢

最佳答案

无需使用单独的 nib 文件,我通过在 AppDelegate 中执行相同的代码

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = self.window.rootViewController.storyboard;
if(condition1) {
UITabBarController *rootViewController= [storyboard instantiateViewControllerWithIdentifier:@"TabbarController"];
[self setRootViewController:rootViewController];
} else if(condition2) {
UIViewController *rootViewController= [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[self setRootViewController:rootViewController];
} else {
UIViewController *rootViewController= [storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
[self setRootViewController:rootViewController];
}
}

-(void)setRootViewController:(UIViewController *)rootViewController {
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
}

关于ios - Storyboard:在运行时设置初始 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27223844/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com