【发布时间】:2014-07-24 13:36:36
【问题描述】:
我有 Singleton 类 APIHTTPClient 负责使用 AFHTTPRequestOperation** 进行 Restful 调用。我有一个场景,用户单击按钮查看视图并调用 APIHTTPClient 以获取新数据以在该视图中显示,但用户也可以单击返回按钮以单击另一个视图并调用 APIHTTPClient 获取新视图的新数据。
当用户点击Back调用另一个restful Request时,如何取消之前的AFHTTPRequestOperation请求。
-(void)CallRemoteService:(int) iModuleID { 静态 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];
【问题讨论】:
标签: ios objective-c multithreading afhttprequestoperation