请参考下图:
我想在“VIEW 1”屏幕或“VIEW 2”屏幕上“直接”启动应用程序,没有“START”屏幕的视觉外观,决定显示VIEW屏幕。
Eg. in loadView() of STARTviewcontroller.m
if (some condition)
{
call "VIEW 1" screen
}
else
{
call "VIEW 2" screen
}
这是最好的方法吗? 我该怎么用segue / [self presentViewController:...] ??
答案 0 :(得分:1)
您需要为两个viewControllers分别设置ID。 然后确定要在AppDelegate级别显示哪个ViewController。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if(someCondition)
{
UIViewController *yourController1= (UIViewController *)[mainStoryboard instantiateViewControllerWithIdentifier: @"viewController1Identifier"];
[self.window.rootViewController presentViewController: yourController1animated:YES completion:nil];
}else{
//instantiate 2ndViewController
`enter code here`
}
}
答案 1 :(得分:0)
从我们在评论中的讨论中我可以理解的是,您根本不需要使用StartViewController
。首先在故事板中制作View1
您的Initial View Controller
。然后在AppDelegate
。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL someCondition;
if (someCondition) {
return YES;
}
else {
UIWindow *keyWindow = application.keyWindow;
UIStoryboard *storyboard = keyWindow.rootViewController.storyboard;
ViewController2 *viewController2 = [storyboard instantiateViewControllerWithIdentifier:@"View2"];
keyWindow.rootViewController = viewController2;
}
return YES;
}
答案 2 :(得分:0)
做一件事。
将“ View1 ”控制器设置为情节提要中的初始视图控制器。
现在以及 didFinishLaunch AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
BOOL showSecondViewController = YES;
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
if (showSecondViewController) {
ViewController2 *objSecondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"ViewController2"];
self.window.rootViewController = objSecondViewController;
[self.window makeKeyAndVisible];
} else {
// It will show First view controller
}
return YES;
}
希望它有所帮助!