Simulate window close button click

Discussion in 'Mac Programming' started by titaniumdecoy, Dec 19, 2007.

  1. titaniumdecoy macrumors member

    Oct 13, 2005
    I thought this was the way to simulate a click on the red close button at the top left corner of a window:

    [NSApp sendAction:mad:selector(performClose:) to:nil from:self];

    Oddly, this does not close the window when there is an open unsaved document. (A save dialog appears, and after it is dismissed the window is still open.) Clicking the window's close button does close the window, however.

    EDIT: Calling the window's -close method does the trick. Sorry to waste anyone's time.
  2. Sijmen macrumors 6502a

    Sep 7, 2005
    First off, you're sending a message to nil - that won't do anything.

    Secondly, as you said, -[NSWindow close] will close the window. If you want to really simulate clicking the close button (ie, with the highlight of the red button etc), use -[NSWindow performClose].
  3. Nutter macrumors 6502

    Mar 31, 2005
    London, England
    No, he's sending a nil-targeted action message, which is delivered to the first responder.
  4. Sijmen macrumors 6502a

    Sep 7, 2005
    Whoops, totally forgot about that. Thanks.

Share This Page