如何解决如何将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 {}
您可以在其中设置标签页名称和图像。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。