How IOS prevents multiple responses due to button quick clicks

Source: Internet
Author: User

Sometimes the action is to prevent the user from responding to the next one at the end of a response. But some test users are going to be a little bit more mad. It's like this kind of malice is going to prevent.

Of course, there are some asynchronous operations that can be removed before they are called. Wait for callback and then enable. The button is not point in the process.

1, can use:

-(void) Timeenough

{

UIButton *btn= (uibutton*) [Self.view viewwithtag:33];

Btn.selected=no;

[Timer invalidate];

Timer=nil;

}

-(void) Btndone: (uibutton*) btn

{

if (btn.selected) return;

Btn.selected=yes;

[Self performselector: @selector (Timeenough) Withobject:nil afterdelay:3.0]; Use delay to limit.

To do something.

2, personally think this method is more useful.

-(void) todosomething: (ID) sender

{

Do the buttons here to do the things you want to do.

}

-(void) starbuttonclicked: (ID) sender

{

The task is canceled before the time of execution.

[Self- class] cancelpreviousperformrequestswithtarget:self selector:@selector (todosomething:) object:sender];

[self performselector:@selector (todosomething:) Withobject:sender afterdelay:0.2f];

}

For the second method, a Quick click N times, as long as each interval within 0.2 seconds of not responding to the operation, wait until the stop click to reach 0.2 seconds before execution. So set the response time to your own needs, and go crazy and respond only once.

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.