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

npm: issue with bower command not found

terminal alias npm bower

I installed bower using node package manager but I always get 'bower command not found'.

C# ASP.Net WebForm Membership Extra User Details (Profile)

c# asp.net

I'm learning how to use the ASP.net membership, when a user registers they just create a username and password, however i want to create a page on my website called "profile" where they can fill in...

UITextView: characters count is not right when the backspace is typed in

objective-c ios uitextviewdelegate

I want to show the characters number when I type in a UITextView. But I'm confused when I presse the delete/backspace key.