Simulate window close button click

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

  1. titaniumdecoy macrumors member

    Joined:
    Oct 13, 2005
    #1
    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

    Joined:
    Sep 7, 2005
    #2
    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

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

    Joined:
    Sep 7, 2005
    #4
    Whoops, totally forgot about that. Thanks.
     

Share This Page