iPhone开发 tabBarController与UINavigationController结合
来源:未知 责任编辑:智问网络 发表时间:2013-08-28 11:56 点击:次
- (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];
//设置委托www.2cto.com
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];
//设置委托www.2cto.com
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"];
}
}
摘自 凡娃软件
相关新闻>>
- 发表评论
-
- 最新评论 更多>>