Search code examples
objective-cviewcontrollerdismissrootviewcontroller

dismiss rootViewController on button tap


I have a viewController instantiated by storyboard on application launch which is a part of hybrid app. On top of that I have presented one more view controller. Now While dismissing the presentedViewController I want to dismiss the rootViewController as well so as to show the hybrid app screen. How can I achieve this?


Solution

  • [self dismissViewControllerAnimated:YES completion:^{
    
    
     // after your second view controller dismissed.
     // set your new view controller as a root of window.
     // You need to set navigation controller and set any root view controller for that navigation controller in storyboard.
    // also don't forget to set identifier of your navigation controller.
    
    
       UINavigationController* rootController = [[UIStoryboard storyboardWithName:kStoryboardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"controllerIdentifier"];
    
       UIWindow* window = [[UIApplication sharedApplication] keyWindow];
       window.rootViewController = rootController; 
    
      // this will set your new navigation controller with root view on UIWindow.
    
    }];