xcode 6自定义标签栏在选中之前不显示图像

时间:2015-01-24 14:22:09

标签: ios objective-c xcode tabs

几年前我写了几个应用程序,这些应用程序都在商店中,并且都是正常的,工作的,批准的等等。

我现在已经在Xcode 6中打开它们来对它们进行一些更新,我编写的自定义标签栏在Xcode 4中工作正常,现在显示出非常奇怪的行为。

第一次加载时条形显示为空白,但是当触摸/选择每个标签时,图像会加载。一旦选择了所有选项卡,则条形图完全正常工作,所有图像都按预期显示 - 但首次加载时,标签栏显示空白(第一个选项卡除外,因为它已被选中)。

enter image description here

代码自从以前工作以来没有改变,所有图像都在那里并且加载正常,因为一旦选择了一个标签,它们就会显示正常。只有在第一次加载时,图像才会显示,直到触摸并选择该标签。

我的自定义标签栏的代码如下所示,之前一切正常,现在可以在商店的应用程序中正常运行:

CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGRect tabbarTopFrame = CGRectMake(0,(screenSize.height - 59),320,10);
UIImageView *tabbarTop = [[UIImageView alloc] initWithFrame:tabbarTopFrame];
tabbarTop.image = [UIImage imageNamed:@"tabbar_top.png"];
[self.tabBarController.view addSubview:tabbarTop];

UIImage *selectedImage0 = [UIImage imageNamed:@"tabbar_introduction_active.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"tabbar_introduction_default.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"tabbar_nests_active.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"tabbar_nests_default.png"];
UIImage *selectedImage2 = [UIImage imageNamed:@"tabbar_home_active.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"tabbar_home_default.png"];
UIImage *selectedImage3 = [UIImage imageNamed:@"tabbar_dogowners_active.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"tabbar_dogowners_default.png"];
UIImage *selectedImage4 = [UIImage imageNamed:@"tabbar_spotted_active.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"tabbar_spotted_default.png"];

UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBar.items objectAtIndex:4];

item0.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item3.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
item4.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];

自Xcode 4以来有关上述代码的更改,或者上述代码是否存在任何问题导致图像在被选中后才会加载?

Xcode没有显示错误或警告,如下所示。

这让我无法忍受悲伤,我只是无法理解这种行为!

2 个答案:

答案 0 :(得分:2)

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];

该功能在iOS7中首先弃用。

替代方案:

[item0 setImage:[unselectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

    [item0 setSelectedImage:[selectedImage0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

答案 1 :(得分:0)

尝试检查文件夹中是否缺少 unselectedimages 。尝试再次删除并重新连接此图像,并确保将它们添加到目标。