Iphone 如何在导航栏中设置选项卡栏?

Iphone 如何在导航栏中设置选项卡栏?,iphone,ios5,xcode4.3,Iphone,Ios5,Xcode4.3,我是iphone开发的新手。目前我正在使用选项卡式应用程序模板做一个项目,该模板包含4个选项卡,其中一个选项卡在表视图中有一个项目列表,单击表单元格时,我想给出一个描述页面。我知道必须使用导航,我成功地显示了导航,但是现在的问题是,我希望在详细信息页面中也有标签栏。但在我的页面中,它不会出现。 现在我正在使用这个代码来实现导航 在DidFinishInAppDelegate中启动 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen

我是iphone开发的新手。目前我正在使用选项卡式应用程序模板做一个项目,该模板包含4个选项卡,其中一个选项卡在表视图中有一个项目列表,单击表单元格时,我想给出一个描述页面。我知道必须使用导航,我成功地显示了导航,但是现在的问题是,我希望在详细信息页面中也有标签栏。但在我的页面中,它不会出现。 现在我正在使用这个代码来实现导航

在DidFinishInAppDelegate中启动

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1 = [[[cardsAvailable1 alloc] initWithNibName:@"cardsAvailable1" bundle:nil] autorelease];
UIViewController *viewController2 = [[[fetchcard1 alloc] initWithNibName:@"fetchcard1" bundle:nil] autorelease];
UIViewController *viewController3 = [[[registration alloc] initWithNibName:@"registration" bundle:nil] autorelease];
UIViewController *viewController4 = [[[logintab alloc] initWithNibName:@"logintab" bundle:nil] autorelease];


self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,viewController3,viewController4, nil];
self.tabBarController.selectedIndex = 3;

navigationController = [[UINavigationController alloc]
                        initWithRootViewController:self.tabBarController];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:navigationController.view];

[self.window makeKeyAndVisible];
[self.navigationController pushViewController:self.detailViewExample动画:是]

和用于选择上的导航

正确的方法是什么?
有人能为我提供解决方案吗?

您的代码或解释中有错误。您没有构建选项卡式应用程序,因为窗口中的第一个视图是NavigationController的视图。代码中有一个危险的地方,因为windows上的第一个视图是navigationcontroller.view,但rootViewController是tabViewController one。不太聪明

您要做的是一个选项卡式应用程序,每个选项卡中都有一个导航控制器:

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] 
                                                    bounds]] autorelease];

UIViewController *viewController1 = [[[cardsAvailable1 alloc] 
                           initWithNibName:@"cardsAvailable1" bundle:nil] autorelease];
UIViewController *viewController2 = [[[fetchcard1 alloc] 
                                initWithNibName:@"fetchcard1" bundle:nil] autorelease];
UIViewController *viewController3 = [[[registration alloc] 
                              initWithNibName:@"registration" bundle:nil] autorelease];
UIViewController *viewController4 = [[[logintab alloc] 
                                  initWithNibName:@"logintab" bundle:nil] autorelease];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];

self.tabBarController.viewControllers = [NSArray arrayWithObjects:
    [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease], 
    [[[UINavigationController alloc] initWithRootViewController:viewController2] autorelease],
    [[[UINavigationController alloc] initWithRootViewController:viewController3] autorelease],
    [[[UINavigationController alloc] initWithRootViewController:viewController4] autorelease], 
nil];

self.tabBarController.selectedIndex = 3;

self.window.rootViewController = self.tabBarController;
[self.window addSubview:tabBarController.view];

[self.window makeKeyAndVisible];

UINavigationController * navController = [[tabBarController viewControllers] objectAtIndex:3];
[navController pushViewController:self.detailViewExample animated:YES];

好的,我做的是,我有大约5个选项卡,每个选项卡都有导航控制器

你可以自定义下面的代码

//Initialize all the object of classes for Tabs and Navigation
Recipes *frstObj= [[Recipes alloc]init];
GalaryView *galObj = [[GalaryView alloc] init];
FavPageView *favObj = [[FavPageView alloc]init];
MyRecipes *addRec = [[MyRecipes alloc]init];
SearchSelection *searchTab = [[SearchSelection alloc] init];
//EnterContactsViewController *addRec = [[EnterContactsViewController alloc]initWithNibName:@"EnterContactsViewController_iPhone" bundle:nil];

[self.window addSubview:frstObj.view];


navContobj1 = [[UINavigationController alloc] init];
navContobj2 = [[UINavigationController alloc] init];
navContobj3 = [[UINavigationController alloc]init];
navContobj4 = [[UINavigationController alloc]init];
navContobj5 = [[UINavigationController alloc]init];

[navContobj1 pushViewController:frstObj animated:YES];
[navContobj2 pushViewController:galObj animated:YES];
[navContobj3 pushViewController:favObj animated:YES];
[navContobj4 pushViewController:searchTab animated:YES];
[navContobj5 pushViewController:addRec animated:YES];
[frstObj release];
[galObj release];
[favObj release];
[searchTab release];
[addRec release];

//Set Title
navContobj2.title = @"Galary";
navContobj3.title = @"Favoruite";
addRec.title = @"Add Recipe";
navContobj4.title = @"Search Recipes";


UITabBarController *tab = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
[tab setViewControllers:[NSArray arrayWithObjects:navContobj1,navContobj2,navContobj3,navContobj4,navContobj5,nil]];




// use extended method to set background color
//[tab setBackground];
 [self copyDatabaseIfNeeded];
// Override point for customization after application launch.
[self.window addSubview:viewController.view];
[self.window addSubview:tab.view];
[self.window makeKeyAndVisible];