在我的UIViewController
我有以下方法:
-(void)setTabBarIcon{
AppDelegate * appDel = [[AppDelegate alloc]init];
UIImage *activeIcon = [appDel makeTabBarImageFromMyFaceWithOptionalRed:YES];
UIImage *inactiveIcon = [appDel makeTabBarImageFromMyFaceWithOptionalRed:NO];
activeIcon = [activeIcon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
inactiveIcon = [inactiveIcon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Jij" image:inactiveIcon selectedImage:activeIcon];
}
它会更改与我的ViewController关联的tabBarItem的图像。
现在,在启动App时,我还需要设置该图像。由于尚未提供所需信息,我在AppDelegate中做了类似的事情:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions2:(NSDictionary *)launchOptions {
UITabBarController *tabb = (UITabBarController *)self.window.rootViewController;
UITabBarItem *myFace = [tabb.tabBar.items objectAtIndex:2];
//myFace.image=[UIImage imageNamed:@"beam.png"];
UIImage *placeholder = [UIImage imageNamed:@"beam.png"];
myFace = [[UITabBarItem alloc] initWithTitle:@"Bla" image:placeholder selectedImage:placeholder];
return YES;
}
两个观察结果:
*myFace = [[UITabBarItem alloc] initWithTitle:*
行没有做任何事,至少对我不可见。*myFace.image=[UIImage imageNamed:@"beam.png"];*
时,实际显示的是图像。TabBarItem
的图像。我想我正在处理TabBarItem
或其他事件的不同实例,但我完全不解,我希望你们中的一个人能够看到我出错的地方。
修改
注意我的UIViewController
嵌入在UINavigationController中可能具有潜在的重要性。所以,层次结构是:
的UITabBarController>&UINavigationController的GT; UIViewController中即可。后者是我用成功设置TabBar图像的地方 - (void)setTabBarIcon
提前感谢您的建议。