Denis (fds) wrote in macosxdev,
Good day, everyone!

Is it possible in Cocoa to create a selector with parameters?

I want to do something like

    NSButton * button = [[NSButton alloc] initWithFrame:NSMakeRect(10, 10, 75, 15)];
    [button setTarget:aWindow];   
    [button setAction:@selector(setBackgroundColor:  <I would add here a color as a parameter>   )];

But I have not found out how to pass a parameter for setBackgroundColor.

May be I should look at NSNotificationCenter for the such functionality?
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

  • 4 comments

sky_thunder

March 30 2009, 18:54:35 UTC 5 years ago

The only parameter an action handler can have is an action sender (ie button, menu item etc). You should find an other way to pass the color to the handler.

fds

March 30 2009, 19:11:26 UTC 5 years ago

ok, thank you!

Deleted comment

fds

March 30 2009, 19:15:33 UTC 5 years ago

Hi eldudeorino,
I agree with you. I just wondered whether this approach could work.

Thank you!

Deleted comment

fds

March 31 2009, 09:18:10 UTC 5 years ago

Hi eldudeorino,

the question was about a possibility to pass any parameters using selectors I took the scenario with NSButton because it come in my mind as an example.

As I understood form documentation and the cocoadev portal, selector is just a signature of a method.