我正在使用UITabbarController
和UINavigationController
来处理我的申请。我用UITabbar
基础应用程序创建了应用程序,我给出了不同类型的导航控制器来导航视图。如下图所示。
但我有一个问题,我描述如下:
假设我有5 ViewController
和3 NavigationViewController
所有五个视图控制器,如View1为rootViewController
,view2为子视图。将第3个RootViewController
视为NavigationViewController
,将第3个subview
视为第3个RootViewController
。
当我运行应用程序时,view1加载为RootViewController
现在我导航到视图2,因为它的视图1的子视图当时我的标签栏被选为第一个标签。当我点击第二个标签栏按钮时,它会显示第2个RootViewController
的{3}为NavigationController
。
现在我点击返回第1 Tabbar
按钮查看视图1但它显示了我的子视图2.如果我需要移动到RootViewController
我需要按回按钮查看我的{ {1}}。
因此,根据我的sinario,可以为该特定标签栏设置RootView,以便用户可以轻松访问RootView,而无需查看所有标签栏点击项目的子视图。
请帮帮我。
答案 0 :(得分:1)
创建三个视图控制器(您需要五个),然后将每个视图控件分配给每个单独的navigationcontrollers。然后将三个navigationcontrollers分配给tabbar,如下所示 -
RideViewController* rideObj = [[RideViewController alloc]initWithNibName:@"RideViewController" bundle:nil];
RequestARideViewController* requestARideObj = [[RequestARideViewController alloc]initWithNibName:@"RequestARideViewController" bundle:nil];
MyAccountViewController* myAccntObj = [[MyAccountViewController alloc]initWithNibName:@"MyAccountViewController" bundle:nil];
navCtrlObj1 = [[UINavigationController alloc]initWithRootViewController:rideObj];
navCtrlObj2 = [[UINavigationController alloc]initWithRootViewController:requestARideObj];
navCtrlObj3 = [[UINavigationController alloc]initWithRootViewController:myAccntObj]
self._tabBarController = [[UITabBarController alloc]init];
self._tabBarController.delegate=self;
self._tabBarController.viewControllers = [NSArray arrayWithObjects:navCtrlObj1,navCtrlObj2,navCtrlObj3,nil];
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
write your code here to move the ViewController as written below.(as your requirement)
[navCtrlObj1 popToRootViewControllerAnimated:YES];
[navCtrlObj2 popToRootViewControllerAnimated:YES];
[navCtrlObj3 popToRootViewControllerAnimated:YES];
}
答案 1 :(得分:0)
创建三个视图控制器,然后将每个视图控件分配给每个单独的navigationcontrollers。然后将三个导航控制器分配给标签栏。
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController setDelegate:self];
self.tabBarController.viewControllers = @[navigationController1, navigationController2,navigationController3];
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
write your code here to move the view
}
答案 2 :(得分:0)
使用此代码。当您单击选项卡时,将显示选项卡的导航控制器的根视图
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
write your code here to move the ViewController as written below.(as your requirement)
[navcontrol1 popToRootViewControllerAnimated:YES];
[navcontrol2 popToRootViewControllerAnimated:YES];
[navcontrol3 popToRootViewControllerAnimated:YES];
}