iOS:NSURLConnection无法取消

时间:2013-04-04 20:11:41

标签: ios uiimageview uiimage nsurlconnection

我正在通过NSURLConnection加载图片。一切正常,期待EDGE模式。  当我NSLog();我的连接(已接收数据)时,旧图像仍在加载(一步一步到connectionDidFinishLoading),即使在[connection cancel];之后也是如此。

我该怎么办?在这种情况下,旧图像仍会在新图像出现之前显示出来。

修改

从A类调用连接:

ProductImageLoader *imageLoader = [[ProductImageLoader alloc] initWithString:productID delegate:self];

[self.queue_3LF addOperation:imageLoader];

这里它将在B级初始化:

- (void)start_XL_ImageDownload
{
    [self.authConnection_N3I cancel];
    self.authConnection_N3I = nil;

    if (self.authConnection_N3I == nil)
    {
        NSMutableURLRequest *request_N3I = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.softridge.ch/images/articles/%@_1_xl.jpg", self.product_id]] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:18.0];

        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

        self.authConnection_N3I = [[NSURLConnection alloc] initWithRequest:request_N3I delegate:self];
    }
}

这是B级堕胎:

- (void)abortRunningProcess
{
    [self.authConnection_N3I cancel];
    self.authConnection_N3I = nil;
}

从A类中调用:

ProductDataParser *PDP = [[ProductDataParser alloc] init];
[PDP abortRunningProcess];

1 个答案:

答案 0 :(得分:0)

刚刚将连接导入到另一个类中。现在它完美无缺。可能是一个代表团错误。