繁体   English   中英

从UITabBarController弹出UIViewController

[英]Pop UIViewController from UITabBarController

我想从TabBar弹出ViewController ,该TabBar是从我的应用程序中的ViewController for Logout功能推入的,我为此放了代码,但只在tabbar弹出,而不是在我的第一个ViewController

在注销按钮操作方法中尝试此代码

AppDelegate *appdelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
LoginVC *viewController = [[LoginVC alloc]initWithNibName:@"LoginVC" bundle:nil];
NSArray *array = @[viewController];
[appdelegate.navController setViewControllers:array];
[appdelegate.tabbarController.view removeFromSuperview];
[[appdelegate tabbarController] removeFromParentViewController];
NSLog(@"array - > %@",array);
[appdelegate.window setRootViewController:appdelegate.navController];

假设您具有以下结构

窗口-UINavigationController-(LoginViewController)-UITabBarController-(VC,VC)

这会工作

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
UINavigationController *navController = (UINavigationController *)appDelegate.window.rootViewController;
[navController popToRootViewControllerAnimated:YES];

您可以使用[self.navigationController popToRootViewControllerAnimated:YES]; 用于将viewController弹出到根viewController中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM