views:

432

answers:

1

I have a custom NSControl that acts as sort of a two dimensional slider where you can drag a handle around the view. I added a few class specific methods and the only ones I overrode were the mouse actions and drawRect. My question is, how do I get it to implement target action? How can I make it behave like a slider and continuously send action messages to a bound target? As of now I can wire it up in interface builder but no action is sent. I've read alot about methods like sendActionOn: and sendAction:to: but I don't know exactly how to use them. If someone would explain it I'm sure I'd get it.

A: 

-sendActionOn: is only relevant if you are subclassing NSControl and implementing a cell, which you are not.

In -mouseDragged: (or whatever method is called from -mouseDragged: to change the slider position), you should just call [[self target] performSelector:[self action]].

Rob Keniger
@Rob: This is wrong for two reasons. First it ignores the responder chain and second it doesn’t pass the sender as parameter. The correct way to do this is `[NSApp sendAction: [self action] to: [self target] from: self]`
Sven