iOS-防止按钮被疯狂点击

iOS系统,按钮如果在短时间内被疯狂快速点击,可能造成App ANR,加上保护。

1
2
3
4
5
6
7
8
9
10
- (void)doSomething:(id)sender
{
// Do something..
}

- (void)starButtonClicked:(id)sender
{
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(todoSomething:) object:sender];
[self performSelector:@selector(doSomething:) withObject:sender afterDelay:0.2f];
}