【发布时间】:2014-02-12 12:46:06
【问题描述】:
在我的应用程序中,我创建了一个按钮。 单击该按钮时,将执行一个长任务,并且在任务启动时禁用该按钮,并在任务完成后重新启用该按钮。 我的问题是即使UIbutton被禁用后,它也会注册click事件并在任务完成后调用相同的方法。
我在下面附上了我的代码:
- (IBAction)sync_data_all:(id)sender {
// disable button on main thread
[NSThread detachNewThreadSelector:@selector(DisableButton) toTarget:self withObject:nil];
UIApplication *app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO;
// long tasks start
[self fetchUNsyncedOrders];
[self DeleteproductCategoryTable];
[self deleteproductTable];
[self deletecustomersGroupsTable];
[self deletefetchCustomersTable];
[self deletefetchCustomersAddress];
[self deletefetchOrders];
[self deletefetchOrderItems];
[self deleteCreateOrdersGroups];
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
[NSThread detachNewThreadSelector:@selector(StartActivityIndicatorIn) toTarget:self withObject:nil];
progress = 0.0f;
[NSThread detachNewThreadSelector:@selector(progressBarProgress) toTarget:self withObject:nil];
@try {
[self productCategoryTable];
progress = 0.3;
[NSThread detachNewThreadSelector:@selector(progressBarProgress) toTarget:self withObject:nil];
[self productTable];
progress = 0.4;
[NSThread detachNewThreadSelector:@selector(progressBarProgress) toTarget:self withObject:nil];
[self customersGroupsTable];
progress = 0.5;
[NSThread detachNewThreadSelector:@selector(progressBarProgress) toTarget:self withObject:nil];
[self fetchCustomersTable];
progress = 0.6;
[NSThread detachNewThreadSelector:@selector(progressBarProgress) toTarget:self withObject:nil];
[self fetchCustomersAddress];
progress = 0.7;
[NSThread detachNewThreadSelector:@selector(progressBarProgress) toTarget:self withObject:nil];
[self fetchOrders];
progress = 0.8;
[NSThread detachNewThreadSelector:@selector(progressBarProgress) toTarget:self withObject:nil];
[self fetchOrderItems];
progress = 1.0;
[NSThread detachNewThreadSelector:@selector(progressBarProgress) toTarget:self withObject:nil];
[self CreateOrdersGroups];
}
@catch (NSException *exception)
{
[NSThread detachNewThreadSelector:@selector(syncNotComplete) toTarget:self withObject:nil];
syncError = YES;
}
@finally {
[self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.0];
}
// long task stop
[indicator stopAnimating];
self.view.userInteractionEnabled = YES;
_btn_sync_outlet.enabled = YES;
_btn_sync_outlet.userInteractionEnabled = YES;
}
- (void)DisableButton {
self.view.userInteractionEnabled = NO;
_btn_sync_outlet.enabled = NO;
_btn_sync_outlet.userInteractionEnabled = NO;
}
【问题讨论】:
标签: ios iphone objective-c ios7 uibutton