"sender" parameter in actions...

Discussion in 'Mac Programming' started by jedirunner, Sep 7, 2007.

  1. jedirunner macrumors member

    Joined:
    Aug 1, 2007
    #1
    Heya guys,

    Yes, it's me again. :)

    I have a question about actions. Suppose I put 3 buttons on a window. Each of those buttons is connected to the same action. In the code for the action, I can use the [sender tag] attribute to get the tag that was set for each button. Then I know which button sent the event, so long as those tags have been set to match in IB and in xcode in the action code.

    So, my question is this... Can the actual 'sender' parameter be compared to anything? For example, if I were to create an outlet in the controller class named "Button1" of type "NSButton", and connect that in IB to the actual button on the window, will this evaluate to true?
    if(sender == Button1)

    I didn't seem to get that working last night and am not sure whether it *should* work or not?

    So my real question is this: Is the 'sender' parameter of the action the same as the button instance if I connect an outlet to the NSButton on the window? Or is the button instance that's been connected just some sort of go-between class instance which can be used to talk to the button, but isn't really the button itself?

    Thanks!

    Kevin
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Yes to everything you said :)

    You probably don't have your IBOutlet connected properly in IB. You can check this with NSLog(@"myButton: %@", myButton); where myButton is your IBOutlet.
     

Share This Page