我有一个自定义URL方案,ViewController
当我转到此URL时,我想打开一个不是根的某个.我已经能够做到这一点,剩下的是推动这一ViewController
进navigationController
从AppDelegate
那里我处理我的网址是这样的:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([[url scheme] isEqualToString:@"njoftime"]) { NSDictionary *getListingResponse = [[NSDictionary alloc]init]; getListingResponse = [Utils getListing:[url query]];; if ([[getListingResponse objectForKey:@"status"] isEqualToString:@"success"]) { ListingViewController *listingView = [[ListingViewController alloc]init]; [self.window.rootViewController.navigationController pushViewController:listingView animated:YES]; return YES; }
但它只启动我的应用程序,而不是ListingViewController
我想要启动.知道我怎么能以不同的方式做到这一点?
如果您使用故事板,那么您可以使用以下行来推送您的VC.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; YOURCLASS *obj=[storyboard instantiateViewControllerWithIdentifier:@"YOUR_CLASS_STORYBOARD_ID"]; [self.window.rootViewController.navigationController pushViewController:obj animated:YES];
更新: -
ListingViewController *listingVC = [[ListingViewController alloc] init]; UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:listingVC]; [self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
要处理从AppDelegate推送和弹出viewControllers ,你需要使用[UIApplication sharedApplication]
它跟踪所有viewControllers,从root 1开始.
为了PUSH从视图控制器的AppDelegate
ListingViewController *listingVC = [[ListingViewController alloc] init]; [(UINavigationController *)self.window.rootViewController pushViewController:listingVC animated:YES];
要POP您刚才介绍的是视图控制器,你需要使用这个代码
[(UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController popViewControllerAnimated:YES ];