[英]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.