iOS development--user clicks Frequently, multiple asynchronous network request cancellation issues?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.