[英]Is there a way to have the App Delegate run the conditional and then chose the storyboard entry point?
如果我使用情节提要,而入口点是供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");
}
是的,你可以这么做。
用以下方法写下您的条件:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
做这样的事情
if(Con1)
{
window.rootViewController = [window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"rootViewController1"];
}
else
{
window.rootViewController = [window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"rootViewController2"];
}
您可以将VC1设置为初始视图控制器(通常),如果您想将VC2呈现为初始控制器,请在appDelegate中执行以下操作:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
[self.window setRootViewController:[storyboard instantiateViewControllerWithIdentifier:@"VC2"]];
[self.window makeKeyAndVisible];
如果您未明确执行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.