iPhone停止ASIFormDataRequest [英] Iphone stop an ASIFormDataRequest

查看:29
本文介绍了iPhone停止ASIFormDataRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我还有一个待处理的ASIFormDataRequest(作为异步任务启动)仍在执行并且用户按下后退"按钮(以弹出视图)时,我的viewController出现了问题.

i have a problem in my viewController when i have a pending ASIFormDataRequest (started as an asynchronous task) that is still executing and the user presses the back button (in order to pop the view).

有什么办法可以停止异步任务吗?

Is there any way to stop that asynchronous task?

我已经读过一种叫做"clearDelegatesAndCancel"的方法,但是我不知道它是否是我要寻找的.

I have read that is a method called "clearDelegatesAndCancel" but i don't know if it is what i'm looking for.

谢谢

推荐答案

要调用 clearDelegatesAndCancel ,必须具有异步运行的ASIFromDataRequest对象的句柄.这意味着您应该将其设置为属性,例如...

Thing is, to call clearDelegatesAndCancel, you have to have a handle to the ASIFromDataRequest object that's running asynchronously. That means you should set it up as an property, like...

@interface MyViewController : UIViewController <ASIHTTPRequestDelegate>
{
    ASIFormDataRequest *theRequest
    ...
}

@property (nonatomic, retain) ASIFormDataRequest *theRequest;

然后,在您的.m文件中,不要声明新的请求对象,只需将您的formdatarequest分配给该类的iVar:

Then in your .m, don't declare a new request object, just assign your formdatarequest to the class's iVar:

@synthesize theRequest;

-(void)viewDidLoad  //or whatever
{
    self.theRequest = [ASIFormDataRequest requestWithUrl:myUrl];
    // then configure and fire the request, being sure to set .delegate to self
}

-(void)viewWillDisappear:(BOOL)animated //or whatever
{ 
   [self.theRequest clearDelegatesAndCancel];
}

 -(void)dealloc
{
    [theRequest release];  //don't not do this.
}

要点是,您需要进行自我设置,以便在异步运行请求的情况下接受与对话的请求.

Point is, you need to set yourself up so that you've GOT the request to talk to while it's running asynchronously.

顺便说一句,这确实是一个好习惯.如果您的视图控制器在请求返回之前消失了(例如,通过从UINavController堆栈中弹出),它将尝试在已释放对象上调用委托方法,然后繁荣.

By the way, this is REALLY good practice. If your viewcontroller goes away (say by getting popped off the UINavController stack) before your request returns, it'll try to call the delegate method on a deallocated object, and boom.

这篇关于iPhone停止ASIFormDataRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆