一起使用 UITabBarController 和 UINavigationController

Using a UITabBarController and a UINavigationController together

当在选项卡栏视图之后单击浏览视图时,2 个选项卡的最佳做法或好方法是什么,其行为类似于 UINavigationController。

我是否为每个选项卡制作一个 UINavigationController?

标签栏是这样创建的:

// Create the tab bar text and images
AViewController *viewA = [[AViewController alloc] init];
BViewController *viewB = [[BViewController alloc] init];

UITabBarItem *tabA = [[UITabBarItem alloc] initWithTitle:@"A" image:[UIImage imageNamed:@"a.png"] tag:1];
UITabBarItem *tabB = [[UITabBarItem alloc] initWithTitle:@"B" image:[UIImage imageNamed:@"b.png"] tag:2]

viewA.tabBarItem = tabA;
viewB.tabBarItem = tabB;

NSArray* controllers = [NSArray arrayWithObjects:viewA, viewB, nil];
self.viewControllers = controllers;

对于导航,您需要像这样为每个创建 UINavigationController

已更新:立即尝试

AViewController *viewA = [[AViewController alloc] init];
BViewController *viewB = [[BViewController alloc] init];

UINavigationController *navA = [[UINavigationController alloc]initWithRootViewController:viewA];
UINavigationController *navB = [[UINavigationController alloc]initWithRootViewController:viewA];

UITabBarItem *tabA = [[UITabBarItem alloc] initWithTitle:@"A" image:[UIImage imageNamed:@"a.png"] tag:1];
UITabBarItem *tabB = [[UITabBarItem alloc] initWithTitle:@"B" image:[UIImage imageNamed:@"b.png"] tag:2]

tabA.tabBarItem = tabA;
tabB.tabBarItem = tabB;

NSArray* controllers = [NSArray arrayWithObjects:navA, navB, nil];
self.viewControllers = controllers;

试试这个