我正在使用标签栏控制器显示自定义标签栏。
为视图控制器创建单独的navigationController。
First *firstViewController = [[First alloc]init];
UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:firstViewController];
Second *secondViewController = [[Second alloc]init];
UINavigationController *secondNavController = [[UINavigationController alloc]initWithRootViewController:secondViewController];
Third *thirdViewController = [[Third alloc]init];
UINavigationController *thirdNavController = [[UINavigationController alloc]initWithRootViewController:thirdViewController];
tabBar.viewControllers = [[NSArray alloc] initWithObjects:firstNavController, secondNavController, thirdNavController, nil];
tabBar.delegate=self;
tabBar.selectedIndex=0;
但是当我尝试在选项卡上单击时弹出到root时,只能访问第3个导航控制器。
所以它只适用于第三个标签,第一个和第二个标签不起作用。
答案 0 :(得分:1)
如果您在tabBarController
之上加载视图控制器,则可以解除加载的视图控制器。
[self.presentingViewController dismissViewControllerAnimated:self completion:nil];
答案 1 :(得分:0)
UINavigationController * navController = (UINavigationController *) [[[tabbarcontroller viewControllers] objectAtIndex: tabbarcontroller.selectedIndex] rootViewController];
答案 2 :(得分:0)
如果您希望弹出所有这些视图控制器,您可能会发现此委托很有用。
- (BOOL)tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController {
//iterate though tabbar-viewcontrollers to pop all of them
//return NO, if you want this to be handled like an action
return NO;
//return YES, if you want this to be handled like a normal selection
return YES;
}
希望有所帮助
答案 3 :(得分:0)
It will pop to rootViewController when tap on the tab.
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
[(UINavigationController*)viewController popToRootViewControllerAnimated:YES];
return YES;
}