3

I have a class that derives from UIControl in which I monitor the touchesBegan/Moved/Ended/Cancelled events. Within those events I call the same events on both super and next responder like so:

[self.nextResponder touchesEnded:touches withEvent:event];
[self sendActionsForControlEvents:UIControlEventTouchUpInside];
[super touchesEnded:touches withEvent:event];

I have a parent control that owns a table view. The cells in the table view each contain one of my custom controls. In order to respond to a click I assign a selector to the control when I am creating it and adding it to the table view cell like so:

[myControl addTarget:self action:@selector(myControlTap:withEvent:)forControlEvents:UIControlEventTouchUpInside]; 
[cell.contentView addSubview:myControl];

The parent control's selector looks like this:

- (void)myControlTap:(id)sender withEvent:(UIEvent *)event{
     //UIEvent is always null!
}

Can someone tell me why UIEvent is always nil? If I use an instance of UIButton instead of my custom UIControl then UIEvent is not nil. Furthermore, if I don't call sendActionsForControlEvents in my control then the parent control will never receive any event notifications.

leebert
  • 83
  • 1
  • 6
  • Just to confirm, what is the output when you put `NSLog(@"%@", event);` in your `myControlTap:withEvent:` method? – Alex Nichol Jul 29 '11 at 22:20

1 Answers1

-1

Change "withEvent" to "forEvent" in the method and the selector.

ManOx
  • 1,935
  • 5
  • 23
  • 37