Skip to content

Instantly share code, notes, and snippets.

@fhefh2015
Created May 2, 2016 14:47
Show Gist options
  • Save fhefh2015/55bb63d49c69779c2a72121cafc800b8 to your computer and use it in GitHub Desktop.
Save fhefh2015/55bb63d49c69779c2a72121cafc800b8 to your computer and use it in GitHub Desktop.
iOS防止按钮快速连续点击造成多次响应的方法
//1.在每次点击时先取消之前的操作
- (void)buttonClicked:(id)sender
{
//这里是关键,点击按钮后先取消之前的操作,再进行需要进行的操作
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(buttonClicked:) object:sender];
[self performSelector:@selector(buttonClicked: )withObject:sender afterDelay:0.2f];
}
//2.点击后将按钮置为不可点击状态,几秒后恢复
-(void)buttonClicked:(id)sender{
self.button.enabled = NO;
[self performSelector:@selector(changeButtonStatus) withObject:nil afterDelay:1.0f];//防止用户重复点击
}
-(void)changeButtonStatus{
self.button.enabled = YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment