下载 iPhone 时弹出视图控制器时来自 ASIHTTPRequest 的 exc_bad_access

发布于 2024-11-30 18:42:17 字数 1110 浏览 4 评论 0原文

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

-(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 中看到队列中没有更多请求,但错误不断显示。我错过了什么吗?

谢谢

I have a custom navigation controller so i made my own back button that does

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

and on the view did load, I request for many images using the 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];
}

Essentially, anytime I send an HTTP request, i just do [self sendRequest:].
When I go to this viewcontroller, then press back before all the images are downloading, I get an EXC_BAD_ACCESS that points to the line where ASIHTTPFormRequest tries to perform the selector. I tried putting

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

in my dealloc method, and i put breakpoints before and after this, and I can see from the GDB that there are no more requests in the queue, but the error keeps showing. Am i missing something?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光下的微笑 2024-12-07 18:42:17

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

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

如果您正在使用它们,还需要删除进度委托等)

Your delegates will likely get called to notify you of the cancellation. You need to remove all the delegates in your dealloc method, eg:

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

(and also progress delegates etc if you're using them)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文