2012-08-02 51 views
0

我有一個iPhone應用程序,其中我使用tabbar.when自定義圖像選擇tabbar我必須顯示一個圖像和取消選擇顯示另一個。我已經成功實現了通過使用appdelegate中的波紋管代碼。 `如何更改tabbar中的圖像而不去該視圖控制器?

UIImage *selectedImage0 = [UIImage imageNamed:@"pinboard_hvr2.png"]; 
    UIImage *unselectedImage0 = [UIImage imageNamed:@"pinboard2.png"]; 



    UIImage *selectedImage2 = [UIImage imageNamed:@"scan_hvr2.png"]; 
    UIImage *unselectedImage2 = [UIImage imageNamed:@"scan2.png"]; 

    UIImage *selectedImage3 = [UIImage imageNamed:@"places_hvr2.png"]; 
    UIImage *unselectedImage3 = [UIImage imageNamed:@"places2.png"]; 


    UITabBar *tabBar = self.tabBarController.tabBar; 
    tabBar.TintColor = [UIColor clearColor]; 
    UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; 
    UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; 
    UITabBarItem *item2 = [tabBar.items objectAtIndex:2]; 


    [item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0]; 
    [item1 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2]; 
    [item2 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3]; 

`但現在我的問題是我在那個按鈕,我需要我的每一個的TabBar圖標secondindex.when點擊查看教程根據在tutorial.but解釋改變我不需要在這裏。我想留在教程視圖本身,但需要更改圖標。任何人都可以幫助我實現這一目標嗎?

回答

1

最後我已經整理出了這個問題。其實它是一件簡單的事情。根據教程按鈕的動作設置你選擇和取消選擇的圖像。例如,如果你有3個按鈕,顯示每個標籤的重要性設置選定的圖像appdelegate.tabbar根據像this.`

TabNavAppDelegate *appdelegate = (TabNavAppDelegate *)[[UIApplication sharedApplication] delegate]; 

    UIImage *unselectedImage0 = [UIImage imageNamed:@"pinboard_hvr2.png"]; 
    UIImage *unselectedImage2 = [UIImage imageNamed:@"scan2.png"]; 

    UIImage *selectedImage3 = [UIImage imageNamed:@"places2.png"]; 
    UITabBar *tabBar = appdelegate.tabBarController.tabBar; 
    tabBar.TintColor = [UIColor clearColor]; 
    UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; 
    UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; 
    UITabBarItem *item2 = [tabBar.items objectAtIndex:2]; 


    [item0 setFinishedSelectedImage:unselectedImage0 withFinishedUnselectedImage:unselectedImage0]; 
    [item1 setFinishedSelectedImage:unselectedImage2 withFinishedUnselectedImage:unselectedImage2]; 
    [item2 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:selectedImage3]; 

`和在第三個按鈕操作的視圖設置回正常方式,因爲它在完成的appdelegate。

0

向AppDelegate發送通知或調用委託方法。在該方法中,如果需要,還可以傳遞參數,並在那裏執行特定的選項卡更改。

希望這會爲你工作。

相關問題