首页 > 技术文章 > UIButton快速点击,只执行最后一次

Zsmile 2016-09-09 13:21 原文

button快速点击时,会导致,同一动作执行多次,常用解决办法:

第一种方法:推荐

//取消执行
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(whenPriceChange) object:nil];
//延时0.2调用
[self performSelector:@selector(whenPriceChange) withObject:nil afterDelay:0.2];

第二种方法:这种对快速点击多次并不会有太大作用,无法控制button的点击方法。

//延时2秒调用
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
      
    });

 

推荐阅读