带导航控制器的 Tabbar 控制器

发布于 2024-11-08 12:04:13 字数 913 浏览 0 评论 0原文

我在导航控制器中添加视图控制器,然后将其添加到选项卡栏控制器。但如果我添加这样的内容,

navigationController.viewControllers = 
        [NSArray arrayWithObjects:rootViewController, rootViewController.photoViewController, nil];


tabBarController.viewControllers = [NSArray arrayWithObjects:tourNavigation,mapNavigation ,browserNavigation,
                                        navigationController,nil];

这不会显示带有第四个导航控制器的选项卡..其他控制器很简单,因为

BrowserViewController *browserView = [[BrowserViewController alloc]initWithNibName:@"BrowserViewController"
                                                                                bundle:nil];

    browserView.title = @"Browser";

    UINavigationController *browserNavigation = [[[UINavigationController alloc]initWithRootViewController:browserView]
                                                 autorelease];

这工作正常..但是使用数组的导航不显示。

I am adding view controller in navigation controller and then adding it to tab bar controller. but if i add this like

navigationController.viewControllers = 
        [NSArray arrayWithObjects:rootViewController, rootViewController.photoViewController, nil];


tabBarController.viewControllers = [NSArray arrayWithObjects:tourNavigation,mapNavigation ,browserNavigation,
                                        navigationController,nil];

This is not showing tab with fourth navigation controller.. other controllers are simple as

BrowserViewController *browserView = [[BrowserViewController alloc]initWithNibName:@"BrowserViewController"
                                                                                bundle:nil];

    browserView.title = @"Browser";

    UINavigationController *browserNavigation = [[[UINavigationController alloc]initWithRootViewController:browserView]
                                                 autorelease];

This is working fine.. but navigation with array is not displaying.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莳間冲淡了誓言ζ 2024-11-15 12:04:13

我认为您不应该像这样设置导航控制器的 viewControllers 数组。相反,请尝试:

navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[navigationController pushViewController:rootViewController.photoViewController animated:NO];

假设您希望在用户点击选项卡时显示照片视图控制器。它将位于导航控制器堆栈的顶部。

I don't think you should be setting the navigation controller's viewControllers array like that. Instead try:

navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[navigationController pushViewController:rootViewController.photoViewController animated:NO];

This is assuming that you want the photo view controller to be showing when the user taps on the tab. It will be on top of the navigation controller's stack.

就像说晚安 2024-11-15 12:04:13

您需要从基于视图的应用程序开始。然后在 appDelegate 文件中创建一个 UITabbarController。

Appdelegate.h

UITabBarController *tabBarController;
// set properties

Appdelegate.m

// Synthsize

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

//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController  
Search * search = [[Search alloc] init];  
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];  

Nearby* nearby = [[Nearby alloc] init];  
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];  

Map* map = [[Map alloc] init];  
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];  

AboutUs* aboutUs = [[AboutUs alloc] init];  
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];  

Favorites* favorites = [[Favorites alloc] init];  
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];  

NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];  
tabBarController.viewControllers = controllers;  

[window addSubview:tabBarController.view];    

您可以相应地管理要在哪个选项卡中放置导航控制器或仅放置视图控制器。

然后在上面提到的每个视图控制器中,您需要实现

- (id)init {}

可以设置选项卡名称和图像的功能。

You need to start with view based application. And then create a UITabbarController in you appDelegate file.

Appdelegate.h

UITabBarController *tabBarController;
// set properties

Appdelegate.m

// Synthsize

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

//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController  
Search * search = [[Search alloc] init];  
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];  

Nearby* nearby = [[Nearby alloc] init];  
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];  

Map* map = [[Map alloc] init];  
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];  

AboutUs* aboutUs = [[AboutUs alloc] init];  
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];  

Favorites* favorites = [[Favorites alloc] init];  
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];  

NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];  
tabBarController.viewControllers = controllers;  

[window addSubview:tabBarController.view];    

You can accordingly manage in which tab you want to place navigation controller or only a view controller.

Then in each of the view controllers mentioned above you need to implement

- (id)init {}

in which you can set Tab name and image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文