- (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"];
}
}
摘自 凡娃軟體