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"];
}
}
{
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"];
}
}
{
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"];
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询