在开发中,我们经常会写倒计时的功能,在解决按钮避免在短时间内多次点击的时候,
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{
[self performSelector:@selector(todoSomething:) withObject:self.btn afterDelay:2.2f];
}
- (void)todoSomething:(UIViewController *)vc{
}