2012-02-13 118 views
0

我的問題是我如何添加UITabBarController的childViewController的圖標。我的代碼是:Iphone UITabBarItem圖像未顯示

UITabBarController *tabBar=[[UITabBarController alloc]init]; 
MyUIViewController *mc=[[MyUIViewController alloc]init]; 
[tabBar addChildViewController:mc]; 
[self.navigationController pushViewController:tabBar animated:YES]; 

在此先感謝。

回答

1

請嘗試通過添加MyUIViewController屬性和財產這

UITabBarController *tabController = [[UITabBarController alloc] init]; 
SomeViewController *viewController = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil]; 
[tabController setViewControllers:[NSArray arrayWithObject:viewController]];//Setting child viewController Array. 
UITabBarItem *item = (UITabBarItem *)[tabController.tabBar.items objectAtIndex:0]; //for first view 
[item setImage:[UIImage imageNamed:@"someImage.png"]]; //Image should be 23px X 23px ,I think so. 
0

我已經解決了這個:

@interface MyUIViewController{ 
    UITabBarItem *tabBarItem; 
} 
@property (nonatomic, retain) UITabBarItem *tabBarItem; 

,然後用圖像初始化:

UITabBarController *tabBar=[[UITabBarController alloc]init]; 
MyUIViewController *mc=[[MyUIViewController alloc]init]; 
mc.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"MyTitle" image:[UIImage imageNamed:@"myImage.png"] tag:0]; 
[tabBar addChildViewController:mc]; 
[self.navigationController pushViewController:tabBar animated:YES]; 
0

我只是發現桌面不區分大小寫,但是設備需要代碼具有相同的字母 - 數量情況(上/下)。確保文件的名稱與大小寫相同(上/下)!

實施例:

上的 「first.png」 磁盤上的文件名稱最好被表示爲 - > self.tabBarItem.image = [UIImage的imageNamed:@ 「第一」];

NOT - NOT --- NOT

self.tabBarItem.image = [UIImage的imageNamed:@ 「第一」];

大寫字母'F'今天踢了我的屁股3個小時!由於這種疏忽,我今天失去了3個小時的生活。希望這可以幫助別人。