Elg*_*ert 12 uiviewcontroller ios appdelegate
我有一个自定义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;
}
Run Code Online (Sandbox Code Playgroud)
但它只启动我的应用程序,而不是ListingViewController我想要启动.知道我怎么能以不同的方式做到这一点?
E-R*_*die 12
要处理从AppDelegate推送和弹出viewControllers ,你需要使用[UIApplication sharedApplication]它跟踪所有viewControllers,从root 1开始.
为了PUSH从视图控制器的AppDelegate
ListingViewController *listingVC = [[ListingViewController alloc] init];
[(UINavigationController *)self.window.rootViewController pushViewController:listingVC animated:YES];
Run Code Online (Sandbox Code Playgroud)
要POP您刚才介绍的是视图控制器,你需要使用这个代码
[(UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController popViewControllerAnimated:YES ];
Run Code Online (Sandbox Code Playgroud)
如果您使用故事板,那么您可以使用以下行来推送您的VC.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
YOURCLASS *obj=[storyboard instantiateViewControllerWithIdentifier:@"YOUR_CLASS_STORYBOARD_ID"];
[self.window.rootViewController.navigationController pushViewController:obj animated:YES];
Run Code Online (Sandbox Code Playgroud)
更新: -
ListingViewController *listingVC = [[ListingViewController alloc] init];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:listingVC];
[self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20465 次 |
| 最近记录: |