Why sendAction: doesn't work while performSelector: does?
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.
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];
加载中,请稍侯......
精彩评论