我有一个自定义 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
我想启动。
知道我该如何做不同的事情吗?
Issue
处理视图控制器的推送和弹出应用程序代理,你需要使用[UIApplication sharedApplication]
它跟踪所有视图控制器,从根视图控制器开始。
Solution
To PUSH视图控制器来自应用程序代理
ListingViewController *listingVC = [[ListingViewController alloc] init];
[(UINavigationController *)self.window.rootViewController pushViewController:listingVC animated:YES];
To POP您刚刚提供的 ViewController,您需要使用此代码
[(UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController popViewControllerAnimated:YES ];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)