我使用以下代码从Internet下载了.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];
}
答案 0 :(得分:2)
假设您的NSImageView
附加为名为IBOutlet
的{{1}},您应该可以使用接收的数据初始化图像,然后设置图像视图以显示图像。
imageView
答案 1 :(得分:1)
UIImage有一个方法+ imageWithData: