2010-04-13 44 views
4

我在我的應用程序中使用了選項卡欄控件,並且希望在我的選項卡中使用默認搜索圖標。我正在製作標籤欄編程,但我無法找到一個屬性,我可以指定UITabBarSystemItemSearch項目,我在蘋果文檔中找到。以下是我的標籤欄代碼在UITabbar中使用默認圖標

CouponsViewController *coupons = [[CouponsViewController alloc] init]; 
    UINavigationController *couponsNavigationController = [[UINavigationController alloc] initWithRootViewController:coupons]; 
    couponsNavigationController.tabBarItem.title = @"Coupons"; 
    couponsNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1]; 
    [coupons release]; 

    SettingsViewController *settings = [[SettingsViewController alloc] init]; 
    UINavigationController *settingsNavigationController = [[UINavigationController alloc] initWithRootViewController:settings]; 
    settingsNavigationController.tabBarItem.title = @"Settings"; 
    settingsNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1]; 
    [settings release]; 

    ProfileViewController *profile = [[ProfileViewController alloc] init]; 
    UINavigationController *profileNavigationController = [[UINavigationController alloc] initWithRootViewController:profile]; 
    profileNavigationController.tabBarItem.title = @"Profile"; 
    profileNavigationController.tabBarItem.image = [UIImage imageNamed:@"profileImg.png"]; 
    profileNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1]; 
    [profile release]; 

    [tabBarController setViewControllers:[NSArray arrayWithObjects:loyaltyNavigationController,searchNavigationController,couponsNavigationController,settingsNavigationController,profileNavigationController,nil] animated:NO]; 
    tabBarController.delegate=self; 
    tabBarController.selectedIndex=0; 

    [window addSubview:tabBarController.view]; 

回答

10

在您要放入標籤欄的UIViewController子類中執行此代碼。這最好在您的視圖控制器的初始化方法進行:

- (id) init 
{ 
    self.title = @"search"; 
    self.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch 
                   tag:0]; 

    return self; 
} 
+0

非常感謝 對其做現在 – pankaj 2010-04-13 08:35:01

+1

請注意,您應該釋放UITabBarItem實例與+1創建,除非您使用自動分配參考 – sgosha 2012-11-02 10:10:22

+0

@sgosha後保留數量數數 – 2013-01-19 19:42:26