2012-02-13 120 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个小时的生活。希望这可以帮助别人。