如何popup包含多个导航控制器的视图层次结构的根视图控制器
我有一个与多个 UINavigationControllers的视图层次结构
现在从一个特定的视图控制器,我想popup到window.rootviewcontroller
我怎样才能做到这一点?
我试过了
[UIApplication sharedApplication] .keyWindow.rootViewController popToRootViewController];
但它不起作用。 请build议。
请注意我想要去window.rootVC。
这不适合我
[self.navigationController popToRootViewControllerAnimated:YES];
只需获取窗口实例并再次设置根视图控制器,因为popToRootViewController
只会popup到特定导航栈的根视图控制器
- (void)popToRoot { AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; UIWindow *mainWindow = appDelegate.window; ViewController *viewControllerObj = [ViewController new]; UINavigationController *navigationObject = [[UINavigationController alloc] initWithRootViewController:viewControllerObj]; [mainWindow setRootViewController:navigationObject]; }
希望这可以帮助。
组
UINavigationController *navController = (UINavigationController*)self.window.rootViewController; [self.navigationController popToRootViewControllerAnimated:YES];