2

如果我使用的是故事板并且入口点是 viewController1。

有没有办法让 App Delegate 运行条件然后选择情节提要入口点 - viewController1 或 viewController2?

我想从 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");

    }
4

3 回答 3

3

是的,你可以这么做。

用以下方法写下你的条件:

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

做这样的事情

if(Con1)
{
   window.rootViewController = [window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"rootViewController1"];
}
else
{
    window.rootViewController = [window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"rootViewController2"];
}
于 2013-02-07T11:54:00.253 回答
1

您可以将 VC1 设置为初始视图控制器(通常),如果您想将 VC2 设置为初始控制器,请在 appDelegate 中执行此操作:

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

如果您没有明确地执行 makeKeyAndVisible,iOS 会使用情节提要中的初始视图控制器自动执行此操作

于 2013-02-07T11:53:15.050 回答
0
    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;
于 2013-02-07T12:11:59.600 回答