簡體   English   中英

一起使用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;

嘗試這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM