5

I have a custom class that supports the target-action mechanism but oddly in this specific case, when I try to call the action by executing:

[NSApp sendAction:action_ to:target_ from:self]

it doesn't work, but this way does:

[target_ performSelector:action_ withObject:self];

Obviously both target_ and action_ have valid values.

This is not a big deal as I got it working.

I just can't figure out why -[NSApplication sendAction:to:from:] would not work, as this looks like a pretty basic operation. I've been using sendAction:... in the past without a problem but there seems to be some significant difference between these two, apart from the fact that sendAction has a mechanism to look for an object that responds to the message if its target is nil.

jscs
  • 63,694
  • 13
  • 151
  • 195
Carlos Barbosa
  • 3,083
  • 5
  • 30
  • 30

1 Answers1

0

Are you sure NSApp isn't nil at the time you do sendAction:to:from:?

If it, nothing will happen. To make sure NSApp is a valid object, perform [NSApplication sharedApplication] at least once, or combine them:

[[NSApplication sharedApplication] sendAction:action_ to:target_ from:self];
RavuAlHemio
  • 2,331
  • 19
  • 22