简体   繁体   中英

Pop UIViewController from UITabBarController

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

Try this code in your logout button action method

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];

Assuming you have following structure

Window - UINavigationController - (LoginViewController) - UITabBarController - (VC,VC)

This would work

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

You can use [self.navigationController popToRootViewControllerAnimated:YES]; for popping the viewController into root viewController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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