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?
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];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.