如何使用块取消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];
有没有办法在按钮操作中取消此请求?
答案 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];
}