Why did my overriden sendActionsForControlEvents: never call?

The UIControl documentation clearly states:

When a user touches a control in a way that matches one or more specific events, UIControl sends sendActionsForControlEvents: itself.

So I did pretty simple. I created a subclass of UIControl and redefined it as follows:

- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents { [super sendActionsForControlEvents:controlEvents]; NSLog(@"- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents"); } 

Then I created an instance of UIControl and added an action-target object as:

 MyCustomControl *twb = [[MyCustomControl alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 80.0f, 80.0f)]; twb.backgroundColor = [UIColor yellowColor]; [twb addTarget:self action:@selector(anyTouch:) forControlEvents:UIControlEventAllTouchEvents]; [self addSubview:twb]; 

I also implemented this -anyTouch: method for the selector, for example:

 - (void) anyTouch:(id)sender { NSLog(@"anyTouch"); } 

What happens: I touch the view from this control, and -anyTouch displays the "anyTouch" log messages while I touch it. But even if I subclass UIControl and override sendActionsForControlEvents :, I do not receive the log message as I should. It's pointless. I rewrote it. He must record this message, damn it. %! ยง $%

+4
source share
2 answers

I ran into the same problem. I do not think UIControl itself uses sendActionsForControlEvents: to send sendAction: to: forEvent :. From what small code examples I saw that this function exists for external users who need to push events to registered goals.

+3
source

This is strange because UIControl docs say:

When a user touches a control in a manner that matches one or more of the specified events, UIControl sends itself sendActionsForControlEvents :. As a result, UIControl sends the action to UIApplication in the sendAction: to: from: forEvent: message.

It looks like we should override sendActionsForControlEvents :, but my overridden method will never be called.

+1
source

All Articles