#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");
}
问问题
246 次
1 回答
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)
并在浏览器上请求然后图像没有显示这就是为什么它可能与您的图像有关的问题尝试另一个图像。
于 2013-04-06T11:03:04.987 回答