简体   繁体   English

UIImage未显示

[英]UIImage not displayed

I am using iOS 7 SDK and Xcode 5. I want to set icons on UITabBarItem. 我正在使用iOS 7 SDK和Xcode5。我想在UITabBarItem上设置图标。 I am using below method. 我正在使用以下方法。

setFinishedSelectedImage: withFinishedUnselectedImage:

It was working till now. 一直到现在。 But suddenly it stopped displaying images. 但是突然它停止显示图像。

I tried below various options : 我尝试了以下各种选择:

[img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

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

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

None of them is working. 他们都没有工作。 Here, img is the image downloaded from URL. 在这里, img是从URL下载的图像。

Then I tried with one of the images in app resource and it was displaying. 然后,我尝试使用应用程序资源中的图像之一进行显示。

After that, I tried using temporary UIImageView with background color to red and set img to this UIImageView , it displayed red color instead of img . 之后,我尝试使用背景颜色为红色的临时UIImageView并将img设置为此UIImageView ,它显示为红色而不是img

But strange part is that I use the same img in other view controllers where it is displayed correctly. 但奇怪的是,我在其他显示正确显示的视图控制器中使用了相同的img

Any idea how to solve this issue? 任何想法如何解决这个问题?

It was my mistake in code. 这是我在代码中的错误。 I had to initialze img to some UIImage on declaration. 我必须在声明时将img初始化为一些UIImage Below is shown what was the issue. 下面显示了问题所在。

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