Cannot Connect to NSDrawer

  • I have created a document project in Xcode with a MyDocument class. I
    added an outlet to a NSDrawer instance and connected the outlet to the
    drawer in Interface Builder. I added a menu item to my MainMenu.nib
    (Test > Test Drawer) that sends a message to the first responder. It
    is picked up by DrawerController (NSWindowController) which sends a
    message to the NSDrawer instance to toggle itself. But the only thing
    is that the outlet to the drawer is not set. So I added a button to
    the MyDocument nib and connected it to the toggle action of the
    drawer. Clicking the button works. Using the menu item does not.

    A copy of my test project is available at:
    http://www.neuromight.com/cocoa/DrawerTest.zip

    Could someone tell me why it's not working the way I want and what I
    should do to fix it?

    Thank you,
    Jason
  • > Could someone tell me why it's not working the way I want and what I
    > should do to fix it?

      I'm not sure what purpose the DrawerController class serves, but
    your drawer outlet is in your NSDocument subclass (MyDocument) ... so
    from within your document class, you could call:

    [_drawer toggle:self];

      ... and that would work.

      So in your MyDocument calss you'd have a method like this:

    - (IBAction)toggleDrawer:(id)sender
    {
        [_drawer toggle:self];
    }

      You can then change your menu to call this instead. The frontmost
    document would respond (first responder) and, via its outlet to the
    drawer, would send the message along as expected.

    --
    I.S.
  • Thanks for your time and your help. That worked!

    Jason

    On 10/22/07, I. Savant <idiotsavant2005...> wrote:
    >> You're right about the MyDocument class being able to receive the message
    >> from the menu. Apple's documentation shows that the Document is in the
    >> responder chain:
    >
    > Works for me. I did this:
    >
    > 1 - Delete the DrawerController class.
    > 2 - Removed references to above class from the MyDocument class (.m/.h).
    > 3 - Commented out the -makeWindowControllers method.
    > 4 - Implemented the -testDrawer: action in MyDocument.
    > 5 - Left the nib exactly as it is.
    >
    > Works perfectly. You're having trouble with one or the other (doc or
    > controller) swallowing the message without working. I'm not *exactly*
    > sure why the document is nil (because when you -addWindowController:
    > the controller's document is set automatically ... in theory), but the
    > entire window controller thing is utterly unnecessary.
    >
    > --
    > I.S.
    >
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today