Image not showing up in UITabBarItem

I am using UITabBar and UITabBarItem. I have an URL of an image. I set UITabBarItem's image to that image using URL. But image is not showing up. If I use any other image from my MacBook, it works. My URL is correct, which I verified by copy pasting in browser. Below is my code. Can anyone see any problem?

UIImage * iconImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:singleMatch.imageUrl]]];
// add UITabBarItem to an array
[tabs addObject:[[UITabBarItem alloc] initWithTitle:singleMatch.realName image:[self convertImage:iconImage toSize:CGSizeMake(40, 30)] tag:i]];
[self.chatTabBar setItems:tabs animated:YES];

I use below method to resize the image to fit in UITabBarItem // resizes given image to specified CGSize

- (UIImage *)convertImage:(UIImage *)image toSize:(CGSize)size
{
    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage * resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return resizedImage;
}

Answers


I solved my problem by using this method. - (void)setFinishedSelectedImage:(UIImage *)selectedImage withFinishedUnselectedImage:(UIImage *)unselectedImageHere, selectedImage is shown when UITabBarItem is selected and inselectedImage is shown when it is not selected.


Need Your Help

Graphics disappear for unknown reason

java swing graphics paintcomponent

I am creating a battleship type game using swing. i draw images in one panel and it shows up fine, but when i draw more images in a different panel it either deletes most if not all of the images i...

Can't handle submit function

jquery asp.net-mvc asp.net-mvc-4 onclick submit

I want to show error message with Viewbag but i can't handle button click function. I couldn't

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.