Launching ViewController from AppDelegate

后端 未结 6 2048
情书的邮戳
情书的邮戳 2021-02-03 09:51

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

6条回答
  •  醉梦人生
    2021-02-03 10:30

    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.


    Solution

    To PUSH ViewController from AppDelegate

    ListingViewController *listingVC = [[ListingViewController alloc] init];
    [(UINavigationController *)self.window.rootViewController pushViewController:listingVC animated:YES];
    

    To POP that ViewController you just presented, you need to use this code

    [(UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController popViewControllerAnimated:YES ];
    

提交回复
热议问题