tabbar界面怎么添加UInavigationcontroller

 我来答
千锋教育
2016-04-14 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
展开全部
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
self.window.backgroundColor = [UIColorwhiteColor];

//生成各个视图控制器
MedicalData* aa = [[MedicalDataalloc]init];
UINavigationController *aaNav = [[UINavigationControlleralloc] initWithRootViewController:aa];
HealthRecord* bb = [[HealthRecordalloc]init];
UINavigationController *bbNav = [[UINavigationControlleralloc] initWithRootViewController:bb];
KonwledgeBase* cc = [[KonwledgeBasealloc]init];
UINavigationController *ccNav = [[UINavigationControlleralloc] initWithRootViewController:cc];
CarePrescription* dd = [[CarePrescriptionalloc]init];
UINavigationController *ddNav = [[UINavigationControlleralloc] initWithRootViewController:dd];
//加入一个数组
NSArray* controllerArray = [[NSArray alloc]initWithObjects:aaNav,bbNav,ccNav,ddNav ,nil];
//创建UITabBarController控制器 (定义在.h中,否在开启arc会自动释放掉,内存访问出错)
tabBarController = [[UITabBarControlleralloc]init];
//设置委托
tabBarController.delegate = self;
//设置UITabBarController控制器的viewControllers属性为我们之前生成的数组controllerArray
tabBarController.viewControllers = controllerArray;
//默认选择第1个视图选项卡(索引从0开始的)
tabBarController.selectedIndex = 0;
//设置TabBarItem的标题与图片//30 * 30
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:0] setTitle:@"体检数据"];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:0] setImage:[UIImageimageNamed:@"check_no.png"]];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:1] setTitle:@"健康档案"];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:1] setImage:[UIImageimageNamed:@"check_yes.png"]];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:2] setTitle:@"知识库"];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:2] setImage:[UIImageimageNamed:@"ckb1.png"]];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:3] setTitle:@"保健处方"];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:3] setImage:[UIImageimageNamed:@"ckb2.png"]];
//读取
UIViewController* activeController = tabBarController.selectedViewController;
if(activeController == aa){
//
}
//把tabBarController的view作为子视图添加到window
[self.windowaddSubview:tabBarController.view];
[self.windowmakeKeyAndVisible];
returnYES;

}
//切换事件
- (void)tabBarController:(UITabBar *)tb didSelectViewController:(UIViewController *__strong)viewController
{
NSLog(viewController.title);
if([viewController.title isEqualToString:@"保健处方"])
{
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:3] setBadgeValue:nil];
//[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:3] setBadgeValue:@"0"];
}
}
育知同创教育
2016-04-12 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
展开全部
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
self.window.backgroundColor = [UIColorwhiteColor];

//生成各个视图控制器
MedicalData* aa = [[MedicalDataalloc]init];
UINavigationController *aaNav = [[UINavigationControlleralloc] initWithRootViewController:aa];
HealthRecord* bb = [[HealthRecordalloc]init];
UINavigationController *bbNav = [[UINavigationControlleralloc] initWithRootViewController:bb];
KonwledgeBase* cc = [[KonwledgeBasealloc]init];
UINavigationController *ccNav = [[UINavigationControlleralloc] initWithRootViewController:cc];
CarePrescription* dd = [[CarePrescriptionalloc]init];
UINavigationController *ddNav = [[UINavigationControlleralloc] initWithRootViewController:dd];
//加入一个数组
NSArray* controllerArray = [[NSArray alloc]initWithObjects:aaNav,bbNav,ccNav,ddNav ,nil];
//创建UITabBarController控制器 (定义在.h中,否在开启arc会自动释放掉,内存访问出错)
tabBarController = [[UITabBarControlleralloc]init];
//设置委托
tabBarController.delegate = self;
//设置UITabBarController控制器的viewControllers属性为我们之前生成的数组controllerArray
tabBarController.viewControllers = controllerArray;
//默认选择第1个视图选项卡(索引从0开始的)
tabBarController.selectedIndex = 0;
//设置TabBarItem的标题与图片//30 * 30
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:0] setTitle:@"体检数据"];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:0] setImage:[UIImageimageNamed:@"check_no.png"]];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:1] setTitle:@"健康档案"];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:1] setImage:[UIImageimageNamed:@"check_yes.png"]];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:2] setTitle:@"知识库"];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:2] setImage:[UIImageimageNamed:@"ckb1.png"]];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:3] setTitle:@"保健处方"];
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:3] setImage:[UIImageimageNamed:@"ckb2.png"]];
//读取
UIViewController* activeController = tabBarController.selectedViewController;
if(activeController == aa){
//
}
//把tabBarController的view作为子视图添加到window
[self.windowaddSubview:tabBarController.view];
[self.windowmakeKeyAndVisible];
returnYES;

}
//切换事件
- (void)tabBarController:(UITabBar *)tb didSelectViewController:(UIViewController *__strong)viewController
{
NSLog(viewController.title);
if([viewController.title isEqualToString:@"保健处方"])
{
[(UITabBarItem *)[tabBarController.tabBar.itemsobjectAtIndex:3] setBadgeValue:nil];
//[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:3] setBadgeValue:@"0"];
}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式