我在故事板中手动添加了UITabbarController,而不是根视图控制器。我添加了tabbar项目并设置了segue关系。当UITabbarController的第一个视图控制器即将呈现时,我还在代码中设置每个tabbar项的图像和标题,但无论我做什么,只有第一个项的图像是可见的。其他项目图像只有在被点击并且实际加载了它们的视图时才可见。任何输入如何解决它?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if ([segue.identifier isEqualToString:@"AfterLogin"]) {
UITabBarController *tabBarController = [segue destinationViewController];
NSArray *tabBarItems = tabBarController.tabBar.items;
UITabBarItem *item1 = tabBarItems[0];
UITabBarItem *item2 = tabBarItems[1];
UITabBarItem *item3 = tabBarItems[2];
UITabBarItem *item4 = tabBarItems[3];
[item1 setImage:[[UIImage imageNamed:@"image1_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item1 setSelectedImage:[[UIImage imageNamed:@"image1_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
item1 = @"";
item1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
[item2 setImage:[[UIImage imageNamed:@"image2_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item2 setSelectedImage:[[UIImage imageNamed:@"image1_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
item2.title = @"";
item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
[item3 setImage:[[UIImage imageNamed:@"image3_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item3 setSelectedImage:[[UIImage imageNamed:@"image3_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
item3.title = @"";
item3.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
[item4 setImage:[[UIImage imageNamed:@"image4_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item4 setSelectedImage:[[UIImage imageNamed:@"image4_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
item4.title = @"";
item4.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
}
}