2013-04-06 87 views
0
#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

簡單如果我們想要使用帶有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 

但是,當我用你給定的圖像URL(http://www.so.cityhi.com/cometchat/plugins/filetransfer/download.php?file=559192_10152684963740198_1083006183_n.jpg

,並要求在瀏覽器上,圖像不顯示,這就是爲什麼它可能與你的形象問題嘗試使用其他圖片爲好。