0

viewController在应用程序启动时由故事板实例化,它是混合应用程序的一部分。除此之外,我还展示了一个视图控制器。现在在关闭时,presentedViewController我也想关闭它rootViewController以显示混合应用程序屏幕。我怎样才能做到这一点?

4

3 回答 3

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

}];
于 2016-01-22T05:49:02.513 回答
1

好的,我对 Worklight 一无所知。或者什么是混合应用程序。所以这可能没有意义。但这是对您问题的严格 iOS 答案。

关闭根视图控制器而不用另一个视图控制器替换它是没有意义的。如果你这样做了,你会让你的应用程序无法与之交互(除了摇晃手机?)。

因此,没有办法像使用子视图控制器一样将其关闭。但你可以删除它。

UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow.rootViewController.view removeFromSuperview];
keyWindow.rootViewController = nil;
于 2016-01-22T06:17:47.650 回答
0
NSMutableArray *viewControllers = [self.navigationController.viewControllers mutableCopy];
[viewControllers removeObjectAtIndex:0];
[self.navigationController setViewControllers:viewControllers];
于 2016-01-22T06:24:12.567 回答