Ios 图像未显示在Uitabritem中

Ios 图像未显示在Uitabritem中,ios,objective-c,uiimage,uitabbaritem,Ios,Objective C,Uiimage,Uitabbaritem,我正在使用UITabBar和uitabaritem。我有一个图像的URL。我使用URL将UITabBarItem的图像设置为该图像。但图像并没有出现。如果我使用MacBook上的任何其他图像,它都可以工作。我的URL是正确的,我通过在浏览器中复制粘贴来验证。 下面是我的代码。有人看到什么问题吗 UIImage * iconImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:single

我正在使用
UITabBar
uitabaritem
。我有一个图像的
URL
。我使用URL将UITabBarItem的图像设置为该图像。但图像并没有出现。如果我使用MacBook上的任何其他图像,它都可以工作。我的URL是正确的,我通过在浏览器中复制粘贴来验证。 下面是我的代码。有人看到什么问题吗

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];
我使用下面的方法来调整图像的大小,以适应UITabBarItem //将给定图像的大小调整为指定的大小

- (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;
}

请看下面的问题,只需实现它,它很容易使用


供参考。您可以选择任何一个。

我使用此方法解决了我的问题。
-(void)设置FinishedSelectedImage:(UIImage*)使用FinishedSelectedImage选择eImage:(UIImage*)取消选择eImage

此处,选中UITableItem时显示selectedImage,未选中时显示inselectedImage。

NSURL URLWithString
不会下载图像。查看
NSURLDownload
以查看下载内容的步骤()@bobnoble it downloads image。我通过在UIImageView中显示它进行了验证。所以这不是问题所在。