I. Description of the business environment
When a view is added with two tableview as Subview, two tableview are maintable and subtable respectively.
When the user clicks on a piece of data on maintable, it sends the data in the network request subtable.
Where there is a problem: for example, when the user clicks on the data on the Maintable frequently, the data in the subtable will appear. So how to cancel the previous network request???
Note: Network requests are asynchronous requests
Ii. solution 1. Instantiate a Afhttprequestoperationmanager object
Afhttprequestoperationmanager *manager = [[Afhttprequestoperationmanager alloc] init];
2. Call the Post method to return a Afhttprequestoperation object
Afhttprequestoperation *operation = [Manager post:urlstr parameters:param success:^ (afhttprequestoperation *operation , id responseobject) { } failure:^ (Afhttprequestoperation *operation, Nserror *error) { }];
3. Determine if the Operation object has been instantiated, and if so, cancel the request operation, and if no, re-execute steps 1th and 22 above.
if (subtableoperation)//If a request has been made, cancel it directly. { [subtableoperation Cancel]; } The request does not exist, re-instantiates a subtableoperation = [apitool getsubtablelistdata:@ "Test" callback:^ (NSNumber *success, ID Response) { //processing network callback data and Reloaddata }]; [Subtableoperation start];
Specific code: Demo_operationofcancel
Transferred from: http://blog.5ibc.net/p/88308.html
iOS development--user clicks Frequently, multiple asynchronous network request cancellation issues?