Shweta Siddannavar
Shweta Siddannavar

Reputation: 5

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?

Upvotes: 0

Views: 1230

Answers (3)

Dave Batton
Dave Batton

Reputation: 8845

OK, I don't know anything about Worklight. Or what a hybrid app is. So this may not make sense. But here's a strictly iOS answer to your question.

It doesn't really make sense to dismiss the root view controller without replacing it with another view controller. If you do, you would leave your app with no way to interact with it (except maybe shaking the phone?).

So there isn't a way to dismiss it as you can with child view controllers. But you can just remove it.

UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow.rootViewController.view removeFromSuperview];
keyWindow.rootViewController = nil;

Upvotes: 1

Sunil Chauhan
Sunil Chauhan

Reputation: 2084

NSMutableArray *viewControllers = [self.navigationController.viewControllers mutableCopy];
[viewControllers removeObjectAtIndex:0];
[self.navigationController setViewControllers:viewControllers];

Upvotes: 0

rushisangani
rushisangani

Reputation: 3385

[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.

}];

Upvotes: 1

Related Questions