次のコードを使用して、インターネットから .jpg ファイルをダウンロードしました。
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://cvcl.mit.edu/hybrid/cat2.jpg"]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
receivedData=[[NSMutableData data] retain]; // etc etc
すべて正常に動作します。ただ、データの扱い方がわかりません。IB で画像ビューを作成したとします。画像を表示するにはどうすればよいでしょうか? 最後のビットは次のとおりです。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// ******do something with the data*********...but how
NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
// release the connection, and the data object
[connection release];
[receivedData release];
}