Buttonが複数回クリックして繰り返し実行する方法の問題を解決する
11842 ワード
NSInteger _currentClickNum;//Save the current value of the tag button is clicked
- (void)tabBt1nClicked:(UIButton *)sender
{
}
or
}
参照ドキュメント:http://stackoverflow.com/questions/28343070/how-do-i-prevent-multiple-event-on-same-uibutton-in-ios/39724239#39724239
iOSボタンの高速連続クリックによる複数回の応答を防止する方法
//Button click event
- (void)tabBt1nClicked:(UIButton *)sender
{
NSInteger index = sender.tag;
if (index == _currentClickNum) {
NSLog(@"Click on the selected current topic, not execution method, avoiding duplicate clicks");
}else {
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(tabBtnClicked:) object:sender];
sender.enabled = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
sender.enabled = YES;
});
_currentClickNum = index;
NSLog(@"Column is the current click:%ld",_currentClickNum);
}
}
or
-(IBAction) buttonClick:(id)sender{
button.enabled = false;
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
// code to execute
}
completion:^(BOOL finished){
// code to execute
button.enabled = true; //This is correct.
}];
//button.enabled = true; //This is wrong.
}
参照ドキュメント:http://stackoverflow.com/questions/28343070/how-do-i-prevent-multiple-event-on-same-uibutton-in-ios/39724239#39724239