// 防止多次调用 #define kPreventRepeatClickTime(_seconds_) \ static BOOL shouldPrevent; \ if (shouldPrevent) return; \ shouldPrevent = YES; \ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((_seconds_) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ \ shouldPrevent = NO; \ }); \
//在要执行的方法前面加上kPreventRepeatClickTime(0.5); 即可解决用户连续快速点击造成多执行的问题 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ kPreventRepeatClickTime(0.5); UIViewController* detailVc = [[UIViewController alloc] init]; [self.navigationController pushViewController:detailVc animated:YES]; } -(void)buttnClick{ kPreventRepeatClickTime(0.5); NSLog(@"点击了: %ld次",++_nums); }