问题
please refer image below :
I want to start app 'directly' on "VIEW 1" screen or "VIEW 2" screen, without visual appearance of "START" screen which decide VIEW screen to display.
Eg. in loadView() of STARTviewcontroller.m
if (some condition)
{
call "VIEW 1" screen
}
else
{
call "VIEW 2" screen
}
Is this best way to do it ? what should i use segue / [self presentViewController: ...] ??
回答1:
Do one thing.
Set "View1" controller as initial view controller in your storyboard.
Now And in your didFinishLaunch of 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;
}
Hope it helps !
回答2:
You need to set IDs repectively for both viewControllers. Then Determine which ViewController to present at AppDelegate level.
- (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`
}
}
回答3:
From our discussion in the comments what I could understand is that you don't need to use StartViewController
at all. First make the View1
your Initial View Controller
in the storyboard. And then just do this in your 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;
}
来源:https://stackoverflow.com/questions/40124945/decide-appearance-screen-ios