关于按钮在短时间内多次点击的问题.

  在开发中,我们经常会写倒计时的功能,在解决按钮避免在短时间内多次点击的时候,

  1.我们可以设置UIButton的enable属性,为NO,或者YES

  2.还可以利用两个方法达到同样的效果,下面为代码.

     可以很好地控制,几秒钟之后按钮点击才能执行方法.

  - (void)btnClick{
      [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(todoSomething:) object:self.btn];
      [self performSelector:@selector(todoSomething:) withObject:self.btn afterDelay:2.2f];
  
  }
  - (void)todoSomething:(UIViewController *)vc{
   
  }
posted @ 2016-07-22 09:49  王晓栋  阅读(234)  评论(0编辑  收藏  举报