简体   繁体   English

有没有办法让App Delegate在条件条件下运行,然后选择情节提要入口点?

[英]Is there a way to have the App Delegate run the conditional and then chose the storyboard entry point?

If I'm using a storyboard and the entry point is for viewController1. 如果我使用情节提要,而入口点是供viewController1使用的。

Is there a way to have the App Delegate run the conditional and then chose the storyboard entry point - either viewController1 or viewController2? 有没有一种方法可以让App Delegate运行条件并选择情节提要入口点-viewController1或viewController2?

I want to make a choice from App Delegate on where location services are turned on or not and then do something like: 我想从App Delegate中选择是否打开位置服务,然后执行以下操作:

   (![CLLocationManager locationServicesEnabled]) 
   {

        self.viewController = [[viewController1 alloc] init];

        NSLog(@"vc is viewController2 from app del. loc svcs off");

    }
    else if ([CLLocationManager locationServicesEnabled])  
    {
        // alert location services denied

        self.viewController = [[viewController2 alloc] init];

        NSLog(@"vc is viewController2 from app del. loc svcs on");

        NSLog(@"core location is on");

    }

Yes You can do that. 是的,你可以这么做。

write your condition in following method: 用以下方法写下您的条件:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Do something like this 做这样的事情

if(Con1)
{
   window.rootViewController = [window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"rootViewController1"];
}
else
{
    window.rootViewController = [window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"rootViewController2"];
}

You can set VC1 as your initial view controller (in general) and if you instead want to present VC2 as your initial controller, do this in the appDelegate : 您可以将VC1设置为初始视图控制器(通常),如果您想将VC2呈现为初始控制器,请在appDelegate中执行以下操作:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
[self.window setRootViewController:[storyboard instantiateViewControllerWithIdentifier:@"VC2"]];
[self.window makeKeyAndVisible];

If you don't explicitly do makeKeyAndVisible, iOS does it automatically with the initial view controller from the storyboard 如果您未明确执行makeKeyAndVisible,iOS将使用情节提要中的初始视图控制器自动进行操作

    NSString *identifier;

    (![CLLocationManager locationServicesEnabled]) {

          identifier = @"UNIQUE_ID_OF_VIEW_CONTROLLER1";
    }

    else if ([CLLocationManager locationServicesEnabled])

    {
          identifier = @"UNIQUE_ID_OF_VIEW_CONTROLLER2";

    }   

    UIViewController *firstView = [storyboard instantiateViewControllerWithIdentifier:identifier];

    // NOW SET IT ROOT VIEW CONTROLLER OF THE APP 
    [self.window setRootViewController:firstView];

    [self.window makeKeyAndVisible];

    return YES;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM