0

AFHTTPRequestOperation **を使用してRestful Callを作成する責任を負うSingletonクラスAPIHTTPClientがあります。ユーザーがボタンをクリックしてビューを表示し、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];
4

1 に答える 1

0

ビュー コントローラーで、 AFHTTPRequestOperation *operation への参照を保持し、次に back press を実行します。

[operation cancel]

于 2014-07-24T13:42:22.873 に答える