2013-07-20 36 views
1

我已經在線大約一個小時,現在試圖找到不同的方式來設置我的標籤欄上的自定義圖像。我正在使用調整大小的類。如果有人熟悉它,它是UIImage+ProportionalFill。我對Objective-C有點新,我對使用AppDelegate.h知之甚少,這裏是我的代碼。隨時給我一個新的,因爲我相信它可能會成爲一個新秀的錯誤。Tabbar項目是空的

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

// [UIApplication sharedApplication].idleTimerDisabled = YES; 
[application setStatusBarStyle:UIStatusBarStyleBlackOpaque]; 
[[UITabBar appearance] setBackgroundColor:[UIColor colorWithRed:0/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]]; 
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 
UITabBar *tabBar = tabBarController.tabBar; 
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0]; 
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1]; 
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2]; 
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3]; 
UITabBarItem *tabBarItem5 = [tabBar.items objectAtIndex:4]; 

UIImage *oldProfile= [UIImage imageNamed:@"profile.png"]; 
UIImage *oldFeed = [UIImage imageNamed:@"feed.png"]; 
UIImage *oldSearch = [UIImage imageNamed:@"search.png"]; 
UIImage *oldNotifications = [UIImage imageNamed:@"notification.png"]; 
UIImage *oldMap = [UIImage imageNamed:@"compass.png"]; 
UIImage *newProfile; 
UIImage *newFeed; 
UIImage *newSearch; 
UIImage *newNotifications; 
UIImage *newMap; 
CGSize newSize = CGSizeMake(30, 30); 
newProfile = [oldProfile imageScaledToFitSize:newSize]; 
newFeed = [oldFeed imageScaledToFitSize:newSize]; 
newSearch = [oldSearch imageScaledToFitSize:newSize]; 
newNotifications = [oldNotifications imageScaledToFitSize:newSize]; 
newMap = [oldMap imageScaledToFitSize:newSize]; 

[tabBarItem1 setFinishedSelectedImage:newFeed withFinishedUnselectedImage:newFeed]; 
[tabBarItem2 setFinishedSelectedImage:newMap withFinishedUnselectedImage:newMap]; 
[tabBarItem3 setFinishedSelectedImage:newSearch withFinishedUnselectedImage:newSearch]; 
[tabBarItem4 setFinishedSelectedImage:newNotifications withFinishedUnselectedImage:newNotifications]; 
[tabBarItem5 setFinishedSelectedImage:newProfile withFinishedUnselectedImage:newProfile]; 

// Override point for customization after application launch. 
UIApplication* app = [UIApplication sharedApplication]; 
app.networkActivityIndicatorVisible = YES; 
return YES; 
} 

編輯我收到的錯誤是:

-[UINavigationController tabBar]: unrecognized selector sent to instance 

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-  [UINavigationController tabBar]: unrecognized selector sent to instance 
` 
+0

那麼問題是什麼?這段代碼給你什麼結果? UITabBarController類的引用指出,「標籤欄項目是通過它們相應的視圖控制器配置的 - 所以你不應該在應用程序委託中這樣做,每個控制器應該提供它自己的標籤欄項目。 – rdelmar

+0

@rdelmar對不起,完全忘了把錯誤。它現在在那裏 –

+0

你不明白這個錯誤嗎?它告訴你,你認爲是一個標籤欄控制器(self.window.rootViewController)實際上是一個導航控制器。 – rdelmar

回答