gpt4 book ai didi

iphone - 取消 ASIHTTPRequest

转载 作者:行者123 更新时间:2023-12-01 18:01:15 27 4
gpt4 key购买 nike

取消正在进行的 ASIHttpRequest 请求的正确位置在哪里?这就是我取消的方式,但是当我 时它继续崩溃在不让请求完成的情况下从一个 View Controller 转移到另一个 View Controller .取消请求可以正常工作,但是当切换回第一个 Viewcontroller 时,它会崩溃。

    -(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

if(!DID_FINISH_REQUEST)
{
[requestNewReleases setDelegate:nil];
[requestNewReleases cancel];
[requestNewReleases clearDelegatesAndCancel];
}
}

最佳答案

ASIHttpRequest documentation在 dealloc 方法中有一个请求被取消的例子:

Safely handling the delegate being deallocated before the request has finished

Requests don’t retain their delegates, so if there’s a chance your delegate may be deallocated while your request is running, it is vital that you clear the request’s delegate properties. In most circumstances, if your delegate is going to be deallocated, you probably also want to cancel request, since you no longer care about the request’s status.

In the example below, our controller has an ASIHTTPRequest stored in a retained instance variable. We call the clearDelegatesAndCancel method in it’s dealloc implementation, just before we release our reference to the request:


- (void)dealloc
{
[request clearDelegatesAndCancel];
[request release];
...
[super dealloc];
}

关于iphone - 取消 ASIHTTPRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9477637/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com