gpt4 book ai didi

objective-c - 禁用重复按钮点击的缓冲

转载 作者:行者123 更新时间:2023-11-29 11:21:07 25 4
gpt4 key购买 nike

当用户点击一个按钮时,一个 Action 开始,但如果用户快速点击按钮 10 次,它将执行 10 次。我想在控制从事件返回之前禁用不会生效。

- (IBAction)btnQuickCheckClick:(id)sender {
@try {
self.btnQuickCheck.enabled = NO ;
// Next line takes about 3 seconds to execute:
[self pollRouter] ;
}
@finally {
self.btnQuickCheck.enabled = YES ;
}
}

最佳答案

您可以在轮询前禁用按钮后运行运行循环来更新 UI:

- (IBAction)btnQuickCheckClick:(id)sender {
self.btnQuickCheck.enabled = NO;
// give some time for the update to take place
[self performSelector:@selector(pollRouterMethod) withObject:nil afterDelay:0.1];
}
- (void)pollRouterMethod {
@try {
[self pollRouter];
} @catch (NSException * e) { }
// re-enable the button
self.btnQuickCheck.enabled = YES;
}

当然,这种方法不能替代在另一个线程上运行时间密集型任务。对于长任务,多线程几乎总是可行的方法。

关于objective-c - 禁用重复按钮点击的缓冲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7101692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com