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!