我有 Singleton 类APIHTTPClient负责使用 AFHTTPRequestOperation ** 进行Restful Call .i有一个senario,用户点击按钮查看View并调用APIHTTPClient获取新数据在该视图中显示,但用户也可以单击“返回”按钮单击另一个视图,并调用APIHTTPClient获取新视图的新数据。
如何在用户单击“返回”以调用另一个休息请求时取消之前的AFHTTPRequestOperation请求。
- (void)CallRemoteService:(int)iModuleID { static NSString * const BaseURLString = @“http://www.raywenderlich.com/demos/weather_sample/”; NSString * string = [NSString stringWithFormat:@“%@ weather.php?format = xml”,BaseURLString];
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
// Make sure to set the responseSerializer correctly
// operation.responseSerializer = [AFXMLParserResponseSerializer序列化程序];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
self.queue = [[NSOperationQueue alloc] init];
答案 0 :(得分:0)
在视图控制器中,保持对AFHTTPRequestOperation *操作的引用,然后再按下:
[operation cancel]