AFHTTPRequestOperation
喜歡在請求操作完成時調用GCD塊。有沒有辦法讓它調用方法選擇器呢?我正在將我的應用程序從ASIHTTPRequest
轉換到AFNetworking,而我的應用程序是圍繞選擇器而不是塊建立的。如何在完成時讓AFHTTPRequestOperation調用選擇器而不是塊?
0
A
回答
3
你可以打電話給你的選擇完成區塊內:
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:urlRequest
success:^(NSURLRequest *completedURLRequest, NSHTTPURLResponse *response, NSDictionary *json) {
[self callMyCustomSuccessMethod:json];
}
failure:^(NSURLRequest *errorRequest, NSHTTPURLResponse *response, NSError *error, id JSON) {
[self callMyCustomErrorMethod:error];
}];
[operation start];
2
不知道AFHTTPRequestOperation
支持基於選擇-回調,但你可以很容易地換一個電話你選擇在一個塊:
success:^(AFHTTPRequestOperation *operation, id responseObject) {
[myDelegate onSuccess:operation];
}
這將適用於下列聲明的回叫方法:
- (void)onSuccess:(AFHTTPRequestOperation*)operation;
相關問題
- 1. AFNetworking,AFHTTPRequestOperation完成塊慢火碼
- 2. AFNetworking AFHTTPRequestOperation塊永遠不會被調用
- 3. 如何在AFHTTPRequestOperation完成時執行函數?
- 4. onActivityResult在Activity啓動時被調用,而不是在完成時調用
- 5. UIBarButtonItem選擇器被調用時viewDidLoad(),而不是隻觸摸
- 6. 如何讓函數暫停,直到NSTimer選擇器完成?
- 7. 如何讓intellij選擇代碼完成建議而不必導航到它?
- 8. FetchRequest完成時完成塊/回調
- 9. 哪些是AFHTTPRequestOperation不會調用成功或失敗塊的可能情況?
- 10. 如何在CAKeyframeAnimation完成時指定選擇器?
- 11. 瓶 - 讓一個HTML選擇選項標籤,而不是選擇
- 12. 如何等待ajax調用完成而不使用'async:false'而不使用回調?
- 13. 使用塊對象而不是選擇器?
- 14. 如何在UIDatePicker中僅禁用日期選擇而不是時間選擇
- 15. jquery自動完成 - 使用選項卡鍵入提前執行而不是選擇自動完成選項
- 16. AFHTTPRequestOperation無響應而不是錯誤
- 17. 如何讓apidocs在sphinx-apidoc中使用包而不是模塊
- 18. 如何編寫CSS代碼而不使用:不是選擇器?
- 19. 如何讓任何時間選擇日期選擇器點火
- 20. AFHTTPRequestOperation塊UI
- 21. 如何讓scriptaculous自動完成回調
- 22. 生成選擇,而不是輸入
- 23. AFNetworking響應失敗塊被調用而不是成功塊
- 24. - [ALAssetsLibrary writeImageToSavedPhotosAlbum:metadata:completionBlock:]不調用完成塊
- 25. iOS日期選擇器與星期而不是完整日期
- 26. 如何使用jQuery而不是選擇器來選擇相對URL?
- 27. 如何使用日期選擇器而不是文本字段?
- 28. 如何讓Python生成器返回None而不是StopIteration?
- 29. getView何時完成調用?
- 30. 如何在選擇時「激活」FragmentTab,而不是之前?