我想使用 ASIHttprequest 库来下载一些文件,我正在使用他们的代码进行测试,但在相同的代码适用于他们的示例时它不起作用
这是我调用他们的视图的代码
QueueViewController *queueViewController = [[QueueViewController alloc] initWithNibName:@"Queue" bundle:nil]; [self.view addSubview:queueViewController.view];
这是发出请求的代码
- (IBAction)fetchThreeImages:(id)sender
{
[imageView1 setImage:nil];
[imageView2 setImage:nil];
[imageView3 setImage:nil];
[networkQueue cancelAllOperations];
[networkQueue setDownloadProgressDelegate:progressIndicator];
[networkQueue setRequestDidFinishSelector:@selector(imageFetchComplete:)];
[networkQueue setShowAccurateProgress:[accurateProgress isOn]];
[networkQueue setDelegate:self];
ASIHTTPRequest *request;
request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/i/logo.png"]] autorelease];
[networkQueue addOperation:request];
request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/i/trailsnetwork.png"]] autorelease];
[networkQueue addOperation:request];
request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/i/sharedspace20.png"]] autorelease];
[networkQueue addOperation:request];
[networkQueue go];
}
- (void)imageFetchComplete:(ASIHTTPRequest *)request
{
UIImage *img = [UIImage imageWithData:[request responseData]];
if (img) {
if ([imageView1 image]) {
if ([imageView2 image]) {
[imageView3 setImage:img];
} else {
[imageView2 setImage:img];
}
} else {
[imageView1 setImage:img];
}
}
}
看起来队列正在正确设置,但下载完成后没有调用 imageFetchComplete 方法。