i’m writing an ap for which, when you press on the button, the button should be disabled for a random amount of time between 0-10seconds and after that, the button becomes active again. However, while the button is disabled, if the user clicks, the click seems to just be queued up waitingg for the button to be enabled and the click will be processed. how would i disable and not enqueue user clicks?
-(void)buttonPressed{
NSLog(@"Button pressed!");
button.userInteractionEnabled=false;
sleep(rand()%10);
progLabel.text=@"button is enabled!";
button.userInteractionEnabled = true;
}
I’m assuming you are using a button that derives from
UIControl(UIButton?). You can take advantage of its existingenabledproperty. Setting the property toNOwill ignore all touch events. See this link for information regardingUIControl.Also, another issue I see in your example is your
sleep()function. I’m not familiar with that function, but it could be blocking the main thread. Be cautious. Instead, you should use an NSTimer. After each interval, you might do this:button.enabled = !button.enabledfor a toggle effect.