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


    default userpic

    Your IP address will be recorded 

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.

ok, thank you!

Deleted comment

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

Thank you!

Deleted comment

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.