我的视图层次结构包含多个 UINavigationControllers
现在从特定的视图控制器,我想弹出到window.rootviewcontroller
我该怎么做?
我试过
[UIApplication sharedApplication] .keyWindow.rootViewController popToRootViewController];
但它不起作用。请建议。
请注意我想去window.rootVC。
这对我不起作用
[self.navigationController popToRootViewControllerAnimated:YES];
答案 0 :(得分:2)
设置
UINavigationController *navController = (UINavigationController*)self.window.rootViewController;
[self.navigationController popToRootViewControllerAnimated:YES];
答案 1 :(得分:2)
只需获取窗口实例并再次设置根视图控制器,因为popToRootViewController
仅弹出到特定导航堆栈的根视图控制器
- (void)popToRoot
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UIWindow *mainWindow = appDelegate.window;
ViewController *viewControllerObj = [ViewController new];
UINavigationController *navigationObject = [[UINavigationController alloc] initWithRootViewController:viewControllerObj];
[mainWindow setRootViewController:navigationObject];
}
希望这有帮助。