iPhone開發 tabBarController與UINavigationController結合

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.