0

I want to change the rootViewController of the keyWindow, to do that I need to dismiss all presented view controllers (or a whole stack of presented view controllers).

I currently use this in AppDelegate,

[[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:NO completion:^{
     UIWindow *window = self.window;
     window.rootViewController = [self makeAnotherVCAsRoot];
}];

I wrote about presentingViewController, so in this case, I'm just lucky as the old rootViewController is the presentingViewController, as no view controllers have defined definesPresentationContext

I personally think that we should find the presented view controller stack, and dismiss it, instead of using rootViewController

onmyway133
  • 38,911
  • 23
  • 231
  • 237
  • If you want to dismiss all presented view controllers, you would generally use an unwind segue. See [Technical Note TN2298](https://developer.apple.com/library/ios/technotes/tn2298/_index.html). – Rob Jul 29 '15 at 04:11
  • @Rob How to do that in code, as I'm not using storyboard – onmyway133 Jul 29 '15 at 04:30
  • If i understand you. then this is what i am doing in my app to dismiss all the presented view controllers `[self dismissModalViewControllerAnimated:NO];` and then `[self.presentedViewController dismissViewControllerAnimated:NO completion:nil];` – M Zubair Shamshad Jul 29 '15 at 05:04
  • @onmyway133 Unwind segues are for storyboards only. – Rob Jul 29 '15 at 05:24
  • @Rob sorry, I mean that I don't want to use storyboard. How to do that in code only ? – onmyway133 Jul 29 '15 at 05:34
  • 1
    try this link may be helps you http://stackoverflow.com/questions/2944191/iphone-dismiss-multiple-viewcontrollers – Anbu.Karthik Jul 29 '15 at 05:35

0 Answers0