0

我正在實施基於分割視圖的應用程序。如何將標籤圖標和標題添加到分割視圖中的標籤項目

我有3個選項卡,用於在我的應用程序中左視圖/根視圖底部的3個根視圖。爲此,我將三個視圖控制器添加到了應用程序刪除的tabbar中。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    RootViewController *tab1 = [[RootViewController alloc] init]; 
    DashboardViewController *tab2=[[DashboardViewController alloc] initWithNibName:@"DashboardViewController" bundle:nil]; 
    SendUpdatesViewController *tab3=[[SendUpdatesViewController alloc] initWithNibName:@"SendUpdatesViewController" bundle:nil]; 


    NSArray *tabViewArray=[[NSArray alloc] initWithObjects:tab1,tab2,tab3,tabBar, nil]; 
    tabBar=[[UITabBarController alloc] init]; 
    [tabBar setViewControllers:tabViewArray]; 

    self.splitViewController.viewControllers = [NSArray arrayWithObjects:tabBar,_detailViewController, nil]; 

    self.window.rootViewController = self.splitViewController; 


    [self.window makeKeyAndVisible]; 
    return YES; 
} 

現在我需要爲這些標籤添加標題圖標和相應的操作。

回答

0

您可以使用title-property爲視圖控制器分配標題。默認情況下,這些標題顯示在標籤欄中。您也可以爲每個控制器自定義UITabbarItem。閱讀更多關於這裏:http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UITabBarItem_Class/Reference/Reference.html#//apple_ref/occ/cl/UITabBarItem

一個很好的解決方案將是覆蓋您的viewcontrollers裏面的「title」和「tabBarItem」屬性,使用惰性實例化來確保屬性設置正確時他們是第一次訪問。這樣你也可以保持這個代碼包含在每個viewcontroller的實現中。

相關問題