0

I am using iOS 7 SDK and Xcode 5. I want to set icons on 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.

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.

But strange part is that I use the same img in other view controllers where it is displayed correctly.

Any idea how to solve this issue?

Geek
  • 8,280
  • 17
  • 73
  • 137
  • Is it not displaying any image at all, or your image looks like a white square. In my case, my tab bar was used to display me a white square for icons which didn't fit the sizes of this link : https://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/IconMatrix.html – zbMax Jan 17 '14 at 08:03
  • @zbMax It is not displayed at all. – Geek Jan 17 '14 at 08:04
  • can you add the code you are using to retrieve your images? – zbMax Jan 17 '14 at 08:06
  • @zbMax I download image and use in many other screens before reaching this screen. Basically these are profile pictures of user's facebook/google plus accounts. As it works in other screens I don't think there is any problem with downloading. – Geek Jan 17 '14 at 08:08
  • Geek can you please reset simulator and restart Xcode may be solve your problem also clean cmd+shift+k – Nimit Parekh Jan 17 '14 at 11:10

1 Answers1

0

It was my mistake in code. I had to initialze img to some UIImage on declaration. 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];
Geek
  • 8,280
  • 17
  • 73
  • 137