在点击按钮时关闭 rootViewController
dismiss rootViewController on button tap
我有一个 viewController
在应用程序启动时由故事板实例化,它是混合应用程序的一部分。除此之外,我还展示了一个视图控制器。现在,在关闭 presentedViewController
的同时,我想关闭 rootViewController
以及显示混合应用程序屏幕。我怎样才能做到这一点?
[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.
}];
好的,我对 Worklight 一无所知。或者什么是混合应用程序。所以这可能没有意义。但这里严格 iOS 回答你的问题。
关闭根视图控制器而不用另一个视图控制器替换它真的没有意义。如果这样做,您将无法与您的应用程序进行交互(除了摇动 phone?)。
所以没有办法像使用子视图控制器那样关闭它。但是你可以删除它。
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow.rootViewController.view removeFromSuperview];
keyWindow.rootViewController = nil;
NSMutableArray *viewControllers = [self.navigationController.viewControllers mutableCopy];
[viewControllers removeObjectAtIndex:0];
[self.navigationController setViewControllers:viewControllers];
我有一个 viewController
在应用程序启动时由故事板实例化,它是混合应用程序的一部分。除此之外,我还展示了一个视图控制器。现在,在关闭 presentedViewController
的同时,我想关闭 rootViewController
以及显示混合应用程序屏幕。我怎样才能做到这一点?
[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.
}];
好的,我对 Worklight 一无所知。或者什么是混合应用程序。所以这可能没有意义。但这里严格 iOS 回答你的问题。
关闭根视图控制器而不用另一个视图控制器替换它真的没有意义。如果这样做,您将无法与您的应用程序进行交互(除了摇动 phone?)。
所以没有办法像使用子视图控制器那样关闭它。但是你可以删除它。
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow.rootViewController.view removeFromSuperview];
keyWindow.rootViewController = nil;
NSMutableArray *viewControllers = [self.navigationController.viewControllers mutableCopy];
[viewControllers removeObjectAtIndex:0];
[self.navigationController setViewControllers:viewControllers];