I have a UIButton in a view. I attach an Event handler to it like this:
[self.button addTarget:self
action:@selector(button_touchUpInside:)
forControlEvents:UIControlEventTouchUpInside];
The handler looks like this:
-(void) button_touchUpInside:(id)sender
{
NSLog(@"%@", ((UIButton *)sender).enabled ? @"ENABLED" : @"DISABLED"); // Logs DISABLED
// Do stuff
}
I disable the button like this:
-(void)setEnabled:(BOOL)enabled
{
enabled_ = enabled;
self.button.enabled = enabled;
}
My problem is that even after I set enabled = NO
on the button a TouchUpInside
still triggers the handler. I can see in the handler that the button is disabled, however the handler is still triggered.
Please note that there are several ways of working around this - checking for button.enabled in the handler, @sanchitsingh's answer below etc. WHat I want to know is why this is happening.