Re: applicationShouldTerminate problem
Re: applicationShouldTerminate problem
- Subject: Re: applicationShouldTerminate problem
- From: Jens Alfke <email@hidden>
- Date: Fri, 4 Dec 2009 09:31:44 -0800
On Dec 3, 2009, at 12:25 AM, proger proger wrote:
int ret = NSRunAlertPanel(@"Save the work?", @"Do you want save the
work?",
A modal alert is the wrong UI here. It should be a sheet on the window.
I used Interface Builder to delegate NSApplication with my delegate
controller. But don't see any results.
It sounds like you just tried closing the window, not quitting the
app. Those are different things.
But i'm still have problem because
then NSAlert is shown(i don't see my application window, it hides)
The method name includes "AFTER last window closed". So after the user
closes the window, the app terminates. The window's already gone by
that point.
What you need to add is the NSWindow delegate method -
windowShouldClose:. This runs when the user tries to close the window.
You should move your save/discard/cancel logic to a separate method,
and then call it from -windowShoudlClose, and also from -
applicationShouldTerminate:. (Strictly speaking the latter should call
it on every open window, but it sounds like your app only has one
window.)
Note that since sheets are not modal, your -windowShouldClose should
always return NO if it puts up the sheet. Then your completion handler
for the sheet can close the window (unless the user canceled.)
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden