【问题标题】:exc_bad_access from ASIHTTPRequest when popping view controller while downloading for iphone为 iphone 下载时弹出视图控制器时来自 ASIHTTPRequest 的 exc_bad_access
【发布时间】:2011-08-21 07:27:00
【问题描述】:

我有一个自定义导航控制器,所以我制作了自己的后退按钮

-(void)navigateBack{
    [self.navigationController popViewControllerAnimated:YES];
}

在视图确实加载时,我使用 ASINetworkQueue 请求了许多图像

-(void)sendRequest:(NSURL *)url withParams:(NSDictionary *)params andSelector:(NSString *)selector{
NSString *jsonString = [params yajl_JSONString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:jsonString forKey:@"json"];
[request setTimeOutSeconds:15];
[[self networkQueue] setDelegate:self];
[[self networkQueue] setRequestDidFinishSelector:NSSelectorFromString(selector)];
[[self networkQueue] setRequestDidFailSelector:@selector(asiRequestFailed:)];
[[self networkQueue] addOperation:request];
[[self networkQueue] go];
}

基本上,每当我发送 HTTP 请求时,我都会执行 [self sendRequest:]。 当我转到这个视图控制器,然后在所有图像下载之前按回,我得到一个 EXC_BAD_ACCESS,它指向 ASIHTTPFormRequest 尝试执行选择器的行。我试着把

[networkQueue cancelAllOperations];[self setNetworkQueue:nil];

在我的 dealloc 方法中,我在此之前和之后放置了断点,我可以从 GDB 中看到队列中没有更多请求,但错误一直显示。我错过了什么吗?

谢谢

【问题讨论】:

    标签: iphone objective-c download asihttprequest exc-bad-access


    【解决方案1】:

    您的代表可能会接到电话通知您取消。您需要删除您的 dealloc 方法中的所有委托,例如:

    for (ASIHTTPRequest *req in [queue operations])
    {
        [req setDelegate:nil];
        [req cancel];
    }
    [queue setDelegate:nil];
    

    (如果您正在使用它们,还有进度代表等)

    【讨论】:

    • 太棒了!这就是我要找的。我不知道如何查看队列中的请求。我查看了 ASIHTTPRequests 的文档,但没有看到类似 forloop 的内容。你怎么知道[queue operations] 是一个请求数组?顺便说一句,我必须将 forloop 中的语句更改为 [req clearDelegatesAndCancel] 才能正常工作
    • 优秀。 ASINetworkQueue 是 NSOperationQueue 的子类(参见 .h 的顶部)——后者具有操作方法(参见 Apple 文档)。不知道为什么 setDelegate:nil 和 cancel 不起作用,但是用 clearDelegatesAndCancel 替换它们很好(对于其他人,asihttprequest
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多