决定外观屏幕 iOS

Decide Appearance Screen iOS

请参考下图:

我想在 "VIEW 1" 屏幕或 "VIEW 2" 屏幕上启动应用程序 'directly',但没有决定要显示的 VIEW 屏幕的 "START" 屏幕的视觉外观。

    Eg.  in loadView() of STARTviewcontroller.m 

 if (some condition)
    {
    call "VIEW 1" screen
    }
    else
    {
    call "VIEW 2" screen
    } 

这是最好的方法吗? 我应该使用什么 segue / [self presentViewController: ...] ??

您需要为两个视图控制器分别设置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`
    }
}

根据我们在评论中的讨论,我可以理解的是您根本不需要使用 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;
}

做一件事。

将“View1”控制器设置为故事板中的初始视图控制器。

现在,在 AppDelegate

didFinishLaunch
- (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;
}

希望对您有所帮助!