Note that there are some explanatory texts on larger screens.

plurals
  1. PONSWindow delegate (windowShouldClose)
    primarykey
    data
    text
    <p>In one of my first Cocoa applications I have just a single window with 2 <code>NSTextField</code> instances - for user text input and of output of text processing.</p> <p>If my user clicks on the red x on the top left, the window closes but the application is still running and icon stays in the dock - the normal Mac behavior.</p> <p>When the user double-clicks on the icon in dock or on the desktop, this does not reopen the window - apparently also normal Mac behavior, but confusing to the user.</p> <p>To get the app back into a running state, the user has to force Quit from the main menu or the context menu, and restart the app by clicking on one of the icons.</p> <p>I searched Apple doc and forums, and it seemed that the following should prevent the closing of the window (my first preference : hide the widow so it can be reopened later) :</p> <ol> <li><p>add a delegate to NSApp</p></li> <li><p>delegate implements <code>-applicationShouldHandleReopen</code> which calls [mainWindow makeKeyAndOrderFront:self]; and returns TRUE</p></li> <li><p>delegate implements <code>-windowShouldClose</code> which returns FALSE However, although <code>-windowShouldClose</code> is called, the window closes.</p></li> </ol> <p>What am I missing here?</p> <p>As an alternative (my second preference), I added to the delegate</p> <ol start="4"> <li><code>-applicationShouldTerminateAfterLastWindowClosed</code> which returns YES</li> </ol> <p>This works, i.e. the application closes when the used clicks on the red x, and the user can restart the app later without further ado.</p> <p>Clarifications and pointers to specific doc and working code examples would be appreciated.</p> <p>Rudi</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload