Reputation: 783
I have a button in my app that calls a long asynchronous function that we do not want to have called multiple times concurrently. However when I start mashing the button, it always sends as many messages as taps. I want to stop the button from responding while the function is running. I currently have a flag that stops execution of the function when the function is active in another thread, and the button is set to be hidden as soon as it enters this function, but these don't have any effect.
Thanks for any help!
Upvotes: 0
Views: 111
Reputation: 73588
Instead of thinking about disabling the button why not make the screen inactive. Show some message like "Processing..." or a Spinner. That way the user will know the something is happening & at the same time your problem is solved.
DSActivityView is a good library for this.
Upvotes: 1
Reputation: 1307
Assuming:
Then you can simply set the button's Enabled property to NO, and re-enabled when you receive notification from your ASYNC task that its done.
-(IBAction) buttonClicked {
[myButton setEnabled:NO];
//Do stuff
}
-(void) notificationHandlerMethodForAsyncTaskDone:(NSNotification *)notification {
[myButton setEnabled:YES];
//Do stuff
}
Upvotes: 1
Reputation: 7707
You can use the enabled
property to turn the button off:
[myButton setEnabled:NO]
Upvotes: 0
Reputation: 2737
Inside the method that handle the touch event you can put disable the button:
- (void)handleTouch:(id)sender {
// Do your asynchronous call
[sender setEnabled:NO];
}
Upvotes: 1