referring to @selector

24 views
Skip to first unread message

jcb

unread,
Sep 12, 2009, 6:48:54 PM9/12/09
to JSTalk Dev
Okay, I've spent all afternoon in Patrick's JSCocoa files and Gus's
JSTalk source code and examples and my head hurts more than ever.

I want to do this:

[button setAction:@selector(sayHello:window)];

or something the equivalent. Could I get a reference to the selector
with this? (Apparently not.)

var message = NSSelectorFromString(sayHello:window);

And while I'm asking, I'd like to use respondsToSelector, but have the
same problem of specifying a selector.

I bow down to youall in advance. Uh..how might I do that?

Ross Boucher

unread,
Sep 12, 2009, 6:52:04 PM9/12/09
to jstal...@googlegroups.com
Just guessing here, but unless that's pseudo code, you aren't passing
a string to NSSelectorFromString. Also, this isn't a valid selector:
@selector(sayHello:window). You're either missing a : after window, or
you are trying to pass an argument using @selector() which doesn't work.

-Ross

Patrick Geiller

unread,
Sep 12, 2009, 7:40:23 PM9/12/09
to jstal...@googlegroups.com

Hello JC,

> Okay, I've spent all afternoon

Why do that ? If you hit a wall after a half hour, send a mail.

> [button setAction:@selector(sayHello:window)];

When using selectors with JSTalk or JSCocoa, just use Javascript
strings and they will be automatically converted.

Use
[button setAction:'sayHello:']
or (Methods starting with 'set' and taking one argument can be called
like this)
button.action = 'sayHello:'

respondsToSelector works the same way :

if ([button respondsToSelector:'sayHello:'])

As Ross said, you can't pass arguments with these. Selectors are just
method names.

-Patrick

jcb

unread,
Sep 12, 2009, 8:19:57 PM9/12/09
to JSTalk Dev
Thanks, merci, thanks. Yeesh. I think I just get confused by all the
layers of scripting-like stuff atop each other. The simplest solution
is often the real one.
Reply all
Reply to author
Forward
0 new messages