#7 Understanding notifications (part 2)

In this Episode, I will illustrate how an observer object can listen to notifications sent by a particular object. I assume you have already watched Episode #6.

As always, feel free to give some feedback about this episode!

3 Comments

  1. Tim says:

    Good stuff. Thank you for taking the time to do this :)
    Can’t wait for the rails with cappuccino stuff.

  2. Sig says:

    Hi Thomas,
    I’m a cappuccino newbie (I discovered it earlier this morning) and after watching this screencast I have a question for you:

    Instead creating two methods (createNewWindowLinkedToLeftSlider and createNewWindowLinkedToRightSlider) that both call createNewWindow with a different parameter, is not possible to call directly createNewWindow in setAction ( [right_button setAction:@selector(createNewWindow ...)] ; )?

    Thanks

  3. Thomas says:

    @Sig : Hi, action messages always take a single argument, which is the object that sent the message, so you can’t pass other arguments. You can read more about the target-action pattern here : http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ObjectiveC/Articles/ocSelectors.html#//apple_ref/doc/uid/TP30001163-CH23-TPXREF132

    What I could have done was to declare button and right_button as 2 ivars, then set their action to @selector(createNewWindow:), and implement createNewWindow like this

    - (void)createNewWindow:(id)sender
    {
    if (sender===button)
    // …
    else // sender===right_button
    // …
    }

    Hope this helps,
    Thomas.