【问题标题】:How to add uitabbarcontroller to uiviewcontroller如何将 uitabbarcontroller 添加到 uiviewcontroller
【发布时间】:2011-09-01 16:49:33
【问题描述】:

我有一个基于视图的应用程序,其中在第一个视图中我不想要标签栏控制器,而从其他视图(即来自第二个视图..)我想要标签栏控制器。 我用谷歌搜索了它,但找不到解决方案。

【问题讨论】:

  • 你好,我也遇到了同样的问题。你能帮我解决这个问题吗

标签: iphone xcode uiview uitabbarcontroller


【解决方案1】:

您需要从基于视图的应用程序开始。然后在你的 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 {}

您可以在其中设置选项卡名称和图像。

【讨论】:

  • 你好,通过 [window addSubview:tabBarController.view];它将从 firstview 添加标签栏。但我想从第二个视图控制器添加标签栏。请帮助我。
猜你喜欢
  • 1970-01-01
  • 2013-08-11
  • 1970-01-01
  • 2011-10-02
  • 1970-01-01
  • 2018-07-14
  • 1970-01-01
  • 1970-01-01
  • 2020-12-05
相关资源
最近更新 更多