- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
//產生各個視圖控制器
MedicalData* aa = [[MedicalData alloc]init];
HealthRecord* bb = [[HealthRecord alloc]init];
KonwledgeBase* cc = [[KonwledgeBase alloc]init];
CarePrescription* dd = [[CarePrescription alloc]init];
//加入一個數組
NSArray* controllerArray = [[NSArray alloc]initWithObjects:aa,bb,cc,dd ,nil];
//建立UITabBarController控制器 (定義在.h中,否在開啟arc會自動釋放掉,記憶體訪問出錯)
tabBarController = [[UITabBarController alloc]init];
//設定委託
tabBarController.delegate = self;
//設定UITabBarController控制器的viewControllers屬性為我們之前產生的數組controllerArray
tabBarController.viewControllers = controllerArray;
//預設選擇第1個視圖選項卡(索引從0開始的)
tabBarController.selectedIndex = 0;
//設定TabBarItem的標題與圖片
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:0] setTitle:@"aa"];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:0] setImage:[UIImage imageNamed:@"1517.png"]]; //30 * 30
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:1] setTitle:@"bb"];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:1] setImage:[UIImage imageNamed:@"light.png"]];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:2] setTitle:@"cc"];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:2] setImage:[UIImage imageNamed:@"podcaste.png"]];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:3] setTitle:@"dd"];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:3] setImage:[UIImage imageNamed:@"setting.png"]];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:4] setTitle:@"ee"];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:4] setImage:[UIImage imageNamed:@"unlock.png"]];
//讀取
UIViewController* activeController = tabBarController.selectedViewController;
if(activeController == aa){
//
}
//把tabBarController的view作為子視圖添加到window
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
摘自 凡娃軟體