ついに私の質問に対する答えを見つけました...私は将来の参考のためにここに貼り付けています
グローバル変数を宣言します
NSMutableData *receivedData;
ViewDidLoadの場合:
receivedData=[[NSMutableData alloc]init];
NSURLRequest *theRequest =[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://wallpaperswide.com/download/flattened_grass-wallpaper-2800x1050.jpg"]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection)
{
}
else
{
// Inform the user that the connection failed.
UIAlertView *connectFailMessage = [[UIAlertView alloc] initWithTitle:@"NSURLConnection " message:@"Failed in viewDidLoad" delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[connectFailMessage show];
}
NSURLConnectionデリゲートメソッド。
#pragma mark NSURLConnection methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// inform the user
UIAlertView *didFailWithErrorMessage = [[UIAlertView alloc] initWithTitle: @"NSURLConnection " message: @"didFailWithError" delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[didFailWithErrorMessage show];
//inform the user
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
UIImage *tmpImage = [[UIImage alloc] initWithData:receivedData];
myImageView.image=tmpImage;
NSLog(@"%@",tmpImage);
}