从AppDelegate启动ViewController [英] Launching ViewController from AppDelegate
问题描述
我有自定义网址方案,我想打开某个 ViewController
,当我转到此网址时,这不是根。我已经能够做到这一点,剩下的就是将 ViewController
从 navigationController
> AppDelegate 我在这里处理我的URL:
I have a custom URL scheme and i want to open a certain ViewController
which is not the root when i go to this URL. I have been able to do that and what remains is pushing this ViewController
into the navigationController
from the AppDelegate
where i handle my URL like this :
- (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
我想发布。
任何想法我怎么能以不同的方式做到这一点?
but it only launches my app and not the ListingViewController
i want to launch.
Any idea how can i do it differently ?
推荐答案
问题
要处理从 AppDelegate 推送和弹出viewControllers,您需要使用 [UIApplication sharedApplication]
来跟踪所有viewControllers ,从根一开始。
Issue
To deal with pushing and popping the viewControllers from AppDelegate, you need to use [UIApplication sharedApplication]
which keeps track to all of viewControllers, beginning with root one.
PUSH 来自 AppDelegate的ViewController
ListingViewController *listingVC = [[ListingViewController alloc] init];
[(UINavigationController *)self.window.rootViewController pushViewController:listingVC animated:YES];
要显示的ViewController POP ,您需要使用此代码
To POP that ViewController you just presented, you need to use this code
[(UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController popViewControllerAnimated:YES ];
这篇关于从AppDelegate启动ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!