Url下载链接图像无法在xcode中查看

时间:2013-04-06 06:55:37

标签: xcode

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize NetImage;

@implementation PlayGameViewController
- (IBAction)imageView:(id)sender {
       //Content of image should be received. But it not show on ImageView.
        NSLog(@"\n Image == %@ ",[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.so.cityhi.com/cometchat/plugins/filetransfer/download.php?file=559192_10152684963740198_1083006183_n.jpg"]]);

        // NetImage is image View.
        NetImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.so.cityhi.com/cometchat/plugins/filetransfer/download.php?file=559192_10152684963740198_1083006183_n.jpg"]]];
        //It working good

        //NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://so.cityhi.com/public/user/52/0052_37ea.png"]];
        //[NetImage setImage:[UIImage imageWithData:data]];
        NSLog(@"Success");
    }

1 个答案:

答案 0 :(得分:1)

简单如果我们想要使用带URL的图像。这只是代码而且你做的很好。

NSString *ImageURL = @"YourURLHere";
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
imageView.image = [UIImage imageWithData:imageData];
//imageView is Your UIImageView That you created in your .h file with IBOutlet

但是当我使用你给定的图片网址(http://www.so.cityhi.com/cometchat/plugins/filetransfer/download.php?file=559192_10152684963740198_1083006183_n.jpg

并在浏览器上请求然后图片没有显示为什么它可能与您的图像有问题也尝试另一个图像。