- (IBAction)fetchThreeImages:(id)sender
{
//清空三个imageview
[imageView1 setImage:nil];
[imageView2 setImage:nil];
[imageView3 setImage:nil];
//初始化一个网络连接对象
if (!networkQueue) {
networkQueue = [[ASINetworkQueue alloc] init];
}
failed = NO;
[networkQueue reset];//重设网络连接对象,如果代理灯一些设置
[networkQueue setDownloadProgressDelegate: test];//设置下载进度条的代理
[networkQueue setRequestDidFinishSelector: @selector(imageFetchComplete:)];//设置下载完成后,所调用的方法
[networkQueue setRequestDidFailSelector: @selector(imageFetchFailed:)];//设置下载失败调用的方法
[networkQueue setShowAccurateProgress: YES];//是否显示详细的进度,就是是否有一个连续的进入显示
[networkQueue setDelegate:self];//设置网络连接对象的代理
ASIHTTPRequest *request;
//设置下载的地址
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/small-image.jpg"]];
//设置下载的文件的保持路径
[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
//设置用于下载显示的进入的进度条
[request setDownloadProgressDelegate: imageProgressIndicator1];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]];
//添加这个下载
[networkQueue addOperation:request];
//同上
request = [ASIHTTPRequest initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/medium-image.jpg"]];
[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"2.png"]];
[request setDownloadProgressDelegate:imageProgressIndicator2];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"request2" forKey:@"name"]];
[networkQueue addOperation:request];
//同上
request = [ASIHTTPRequest initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]];
[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"3.png"]];
[request setDownloadProgressDelegate:imageProgressIndicator3];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"request3" forKey:@"name"]];
[networkQueue addOperation:request];
//开始下载
[networkQueue go];
}
{
//清空三个imageview
[imageView1 setImage:nil];
[imageView2 setImage:nil];
[imageView3 setImage:nil];
//初始化一个网络连接对象
if (!networkQueue) {
networkQueue = [[ASINetworkQueue alloc] init];
}
failed = NO;
[networkQueue reset];//重设网络连接对象,如果代理灯一些设置
[networkQueue setDownloadProgressDelegate: test];//设置下载进度条的代理
[networkQueue setRequestDidFinishSelector: @selector(imageFetchComplete:)];//设置下载完成后,所调用的方法
[networkQueue setRequestDidFailSelector: @selector(imageFetchFailed:)];//设置下载失败调用的方法
[networkQueue setShowAccurateProgress: YES];//是否显示详细的进度,就是是否有一个连续的进入显示
[networkQueue setDelegate:self];//设置网络连接对象的代理
ASIHTTPRequest *request;
//设置下载的地址
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/small-image.jpg"]];
//设置下载的文件的保持路径
[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"1.png"]];
//设置用于下载显示的进入的进度条
[request setDownloadProgressDelegate: imageProgressIndicator1];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]];
//添加这个下载
[networkQueue addOperation:request];
//同上
request = [ASIHTTPRequest initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/medium-image.jpg"]];
[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"2.png"]];
[request setDownloadProgressDelegate:imageProgressIndicator2];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"request2" forKey:@"name"]];
[networkQueue addOperation:request];
//同上
request = [ASIHTTPRequest initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]];
[request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"3.png"]];
[request setDownloadProgressDelegate:imageProgressIndicator3];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"request3" forKey:@"name"]];
[networkQueue addOperation:request];
//开始下载
[networkQueue go];
}
此代码实现了一个功能,通过网络连接获取多个图片,并将其下载到指定路径,然后更新UI显示这些图片。
94

被折叠的 条评论
为什么被折叠?



