【问题标题】:UIImage not displayedUIImage 不显示
【发布时间】:2014-01-17 07:58:15
【问题描述】:

我正在使用 iOS 7 SDK 和 Xcode 5。我想在 UITabBarItem 上设置图标。我正在使用以下方法。

setFinishedSelectedImage: withFinishedUnselectedImage:

它一直工作到现在。但突然它停止显示图像。

我尝试了以下各种选项:

[img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

[tabBarItem setSelectedImage:img];
[tabBarItem setImage:img];

[[UITabBarItem alloc] initWithTitle:title image:img selectedImage:img];

它们都不起作用。这里img是从URL下载的图片。

然后我尝试使用应用资源中的一张图片,它正在显示。

之后,我尝试使用背景颜色为红色的临时UIImageView 并将img 设置为此UIImageView,它显示红色而不是img

但奇怪的是我在其他正确显示的视图控制器中使用了相同的img

知道如何解决这个问题吗?

【问题讨论】:

  • 是根本不显示任何图像,还是您的图像看起来像一个白色方块。在我的情况下,我的标签栏用于向我显示一个白色方块,用于显示不适合此链接大小的图标:developer.apple.com/library/ios/documentation/userexperience/…
  • @zbMax 根本不显示。
  • 您可以添加用于检索图像的代码吗?
  • @zbMax 在到达此屏幕之前,我会下载图像并在许多其他屏幕中使用。基本上这些是用户的 facebook/google plus 帐户的个人资料图片。因为它可以在其他屏幕上运行,所以我认为下载没有任何问题。
  • 极客你能重置模拟器并重新启动 Xcode 可能会解决你的问题也干净 cmd+shift+k

标签: ios objective-c ios7 uiimage uitabbaritem


【解决方案1】:

这是我的代码错误。我必须在声明时将img 初始化为一些UIImage。 下面显示了问题所在。

UIImage * img;  // Image not initialized

// This condition was not satisfied and hence `img` was not storing any time.
if (condition)
{
    img = ...;
}

// Below condition should have been satisfied if `img` was not initialized.
// But it did not. I am not getting why.
if (!img)
{
    NSLog(@"Image is nil");
}

[tabBarItem setImage:img];

【讨论】:

    猜你喜欢
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    • 2015-04-11
    • 2013-06-17
    • 2017-04-26
    • 2023-03-05
    相关资源
    最近更新 更多