0

我想使用 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 方法。

4

2 回答 2

1

尝试requestDidFailSelector在您的实例上设置,以及在每个实例上ASINetworkQueue设置和。从委托中的每个回调方法调用 NSLog() 以查看发生了什么。didFinishSelectordidFailSelectorASIHTTPRequest

请注意,通过启用showAccurateProgress您的ASINetworkQueue,将为队列处理的每个请求完成一个额外的 HEAD 请求。在移动环境中,这有时可能不太理想。

于 2009-11-02T07:36:52.693 回答
1

我解决了这个问题,问题是我没有分配网络队列。

我在没有被调用的 awakefromnib 中分配了 networkQueue。所以我在按钮点击方法中分配networkQueue。这解决了这个问题。

于 2009-11-02T17:35:28.407 回答