如何在iPhone中取消ASIFormDataRequest

时间:2012-05-28 11:17:27

标签: iphone objective-c ios asihttprequest asiformdatarequest

如何使用块取消ASIFormDataRequest?

__block ASIFormDataRequest *req = [ASIFormDataRequest requestWithURL:url];  

[req appendPostData:[str dataUsingEncoding:NSUTF8StringEncoding]];
[req setDelegate:self];
[req setCompletionBlock:^{
    [self parseResult:req];
}];
[req setFailedBlock:^{
    [self requestWentWrong:req];
}];
[req setTag:tag];
[req startAsynchronous];

有没有办法在按钮操作中取消此请求?

1 个答案:

答案 0 :(得分:1)

在您的按钮操作事件中添加此代码,因为req是类成员变量:

-(IBAction)YourbuttonactionEvent
{ 
  if(![req isCancelled]) 
  {
    // Cancels an asynchronous request
    [req cancel];
    // Cancels an asynchronous request, clearing all delegates and blocks first
    [req clearDelegatesAndCancel];
}