What I want to do is set up a bunch of UIControl
objects to send all events through the same handler. That handler than needs to determine what the appropriate action is based on the UIControlEvents
type that triggered.
- (void)handleEventFromControl:(id)sender withEvent:(UIEvent *)event {
UIControl *control = sender;
NSIndexPath *indexPath = [controlIndexPaths objectForKey:control];
UIControlEvents controlEventType = event.type; //PROBLEM HERE
BOOL fire = NO;
NSNumber *eventCheck = [registeredEventsByToolkitIndex objectAtIndex:indexPath.toolkit];
fire = ([eventCheck integerValue] & controlEventType);
if(!fire) {
eventCheck = [registeredEventsByControlIndex objectAtIndex:indexPath.control];
fire = ([eventCheck integerValue] & controlEventType);
}
if(!fire) {
eventCheck = [registeredEventsByIndexPath objectForKey:indexPath];
fire = ([eventCheck integerValue] & controlEventType);
}
if(fire) {
[self.delegate toolkit:self indexPath:indexPath firedEvent:event];
}
}
As best as I can tell, event.type
doesn't work this way. I want to avoid having a subclass of UIControl
because that is severe overkill for what I want to do. The rest of the moving parts here aren't really that important; what I want is a way to check against UIControlEvents
after the target:action:
pair is used in the following setup:
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
If there is a different way to setup of a target:action:
that sends back the UIControlEvents
, I'd take that. But I am not seeing it in the documentation. Or, at the very least, get access outside of the UIControl
object such that I can get the type I want.
You're correct; UIEvent.type
does not work that way. Internally, UIControl
subclasses are basically using the sendActionsForControlEvents:
method, which means they can choose to put anything they want as the parameter.
As for how to know, the simple answer is to have a separate method for each control event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With