繁体   English   中英

UIImage未显示

[英]UIImage not displayed

我正在使用iOS 7 SDK和Xcode5。我想在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

任何想法如何解决这个问题?

这是我在代码中的错误。 我必须在声明时将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];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM