windowShouldClose_ action question

Dear friends,

I am trying to set my to quit if the user closes the main window.

I have tried putting this into delegate:

on windowShouldClose_(aNotification)
display dialog “are you closing this window?”
end windowShouldClose

But nothing happens when I close the window.

I tried connecting the action to the window, but it won’t let me.

Can someone help me?

What am I doing wrong?

Thanks!

The method “on windowShouldClose_(_aNotification)” requires that it returns true or false. If you don’t return T/F then the method stalls out/fails.
So, you need to do something like …

on windowShouldClose_(aNotification)
display dialog “Are you closing this window?” buttons {“No”, “Yes”}
if button returned of result is “Yes” then
return true
else
return false
end if
end windowShouldClose

Hi,

windowShouldClose_() expects a boolean return value to tell the window controller whether the window should be really closed.
To quit an app better use the application delegate method applicationShouldTerminateAfterLastWindowClosed_() and return YES

Hi SuperMacGuy,

Thanks for replying…

I pasted you code into my app delegate, run and still, nothing happens…

Do I have to connect the action?

Hi StefanK,

Thanks!

This works:

on applicationShouldTerminateAfterLastWindowClosed_()

return YES

end applicationShouldTerminateAfterLastWindowClosed_