我想用ASIHttprequest库下载一些文件,我与他们的代码测试和而相同的代码工作对他们的样品是不能正常工作

这是我的代码调用他们认为

  

QueueViewController   * queueViewController = [[QueueViewController的alloc]   initWithNibName:@ “队列” 束:无];     [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方法。

有帮助吗?

解决方案 2

我的问题固定的,问题是,我没有ALLOC networkQueue。

我是在它没有被调用的awakefromnib ALLOC networkQueue。所以我ALLOC networkQueue在按钮点击方法。这解决了该问题。

其他提示

尝试在您requestDidFailSelector的实例设置ASINetworkQueue,以及关于didFinishSelector的每个实例设置didFailSelectorASIHTTPRequest。从调用每个这样的回调方法的NSLog()在您的委托,看看发生了什么。

请注意,通过使在您showAccurateProgress ASINetworkQueue,附加HEAD请求为每个请求该队列过程完成。这有时可以小于理想的在移动上下文。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top