0

I have another question.

I've made an exit window to display when the user hits the "Exit" button or uses "Cmd-Q". The window itself has its own "Exit" button. How do I make it such that the window can be displayed upon Cmd-Q or hitting the "Exit" button? I also cannot attach the AppDelegate to the window. (blue box that represents the appdelegate is missing in IB) I'll provide more information if needed.

I'm using OSX 10.6.8 Snow Leopard, Xcode 4.2

1 Answers1

1

You can connect the button to the application's terminate action, and call the exit window code from the application delegate's applicationWillTerminate method. The application delegate instance can be restored in the Interface Editor by adding a new object (from the object library) and setting its class to your AppDelegate.

  • Any idea how do I connect the button to the application's terminate action? How do I go around setting it's class? Thanks for the answer. :) – Terrence Neo Aug 01 '12 at 03:06
  • In the Interface Editor, connections can be made in a few different ways. One way would be to click on an object and look in the Connections Inspector for all the various outlets and actions - a connection can be made by dragging from the connector (the circle to the right of the name) to the desired object. The class of an object can be set from the Identity Inspector - your script(s) will be listed along with the other classes. –  Aug 02 '12 at 01:57
  • Thanks for the answer, also, I was just looking for how to display a window. I tried "display window". I still don't know what is the specific command to use for that. – Terrence Neo Aug 03 '12 at 05:52
  • Take a look at the NSWindow Class Reference, for example the orderFront: or makeKeyAndOrderFront: methods. –  Aug 03 '12 at 16:15
  • I've tried "makeKeyAndOrderFront ExitMenu", where ExitMenu is the name of the .xib of the window. I don't really know the syntax. – Terrence Neo Aug 05 '12 at 12:22
  • The method needs to be used with the window you are wanting to move to the front, for example **myWindow's makeKeyAndOrderFront_(me)** or **tell myWindow to makeKeyAndOrderFront_(me)** –  Aug 05 '12 at 15:20
  • Hmm...thanks for the information, but now the window does not show up at all when I cmd-q. I have this line property "ExitMenu: window". I currently don't know how to implement this. I linked the xib's window though. Thanks for all the help so far. – Terrence Neo Aug 07 '12 at 09:01