如何将uitabbarcontroller添加到uiviewcontroller

问题描述

|| 我有一个基于视图的应用程序,其中在第一个视图中我不希望使用Tabbar控制器,而在其他视图(即从第二个视图中..)之外的其他视图中,我想要使用Tabbar控制器。 我用谷歌搜索,但找不到解决方案。     

解决方法

您需要从基于视图的应用程序开始。然后在您的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 {}
您可以在其中设置标签页名称和图像。