Connexion au firstResponder depuis le code

13:38 modifié dans API AppKit #1
Bonjour,

Comme le titre l'indique, je souhaiterais connecter un NSMenuItem (ou éventuellement tout autre élément) à  la boite orange, le first responder...

Savez vous si cela est possible ? Et comment ?

Merci.
Michaël

Réponses

  • Philippe49Philippe49 Membre
    13:38 modifié #2
    Extrait de Cocoa Fundamental Guide

    The Target
    A target is a receiver of an action message. A control or, more frequently, its cell holds the target of its action message as an outlet (see “Outlets”). The target usually is an instance of one of your custom classes, although it can be any Cocoa object whose class implements the appropriate action method.

    You can also set a cell's or control's target outlet to nil and let the target object be determined at run time. When the target is nil, the NSApplication object searches for an appropriate receiver in a prescribed order:

    It begins with the first responder in the key window and follows nextResponder links up the responder chain to the NSWindow object's content view.
    Note: A key window responds to key presses for an application and is the receiver of messages from menus and dialogs. An application's main window is the principal focus of user actions and often has key status as well.
    It tries the NSWindow object and then the window object's delegate.
    If the main window is different from the key window, it then starts over with the first responder in the main window and works its way up the main window's responder chain to the NSWindow object and its delegate.
    Next, the NSApplication object tries to respond itself. If it can't respond, it tries its own delegate. NSApp and its delegate are the receivers of last resort.


    Il me semble qu'un
    [myMenuItem setAction:....]
    [myMenuItem setTarget:nil];
    devrait marcher, pourvu qu'une instance dans la chaà®ne des Responder puisse y répondre.
  • Philippe49Philippe49 Membre
    juillet 2008 modifié #3
    Et voici un exemple où on connecte programatiquement l'item Close à  une action d'un Application delegate 
Connectez-vous ou Inscrivez-vous pour répondre.