How IOS prevents multiple clicks of a button multiple times response _ios

Source: Internet
Author: User

How IOS prevents multiple clicks on a button multiple times

A bug is often encountered in daily development because the user clicks a button quickly, causing the page to repeat the push or repeat the network request. Such problems can have an impact on the user experience, but also increase the pressure on the server to some extent.

At present, I use the following two methods to prevent Quick click of button

1. Cancel the previous operation on each click (the method you see online)

-(void) buttonclicked: (ID) sender
{
  //Here is the key, click the button to cancel the previous operation before doing what needs to be done
  [[Self class] Cancelpreviousperformrequestswithtarget:self selector: @selector (buttonclicked:) Object:sender];
  [Self performselector: @selector (buttonclicked:) Withobject:sender afterdelay:0.2f];
}

2. Click to put the button is not clickable state, after a few seconds to restore

-(void) buttonclicked: (ID) sender{
  self.button.enabled = NO;
  [Self performselector: @selector (changebuttonstatus) Withobject:nil afterdelay:1.0f];//prevents users from repeatedly clicking
}

-(void ) changebuttonstatus{
  self.button.enabled = YES;


or 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.
}

If we have a better solution, you are welcome to leave a note.

Thank you for reading, I hope to help you, thank you for your support for this site!

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.