Fwd: applicationShouldTerminate problem
Fwd: applicationShouldTerminate problem
- Subject: Fwd: applicationShouldTerminate problem
- From: proger proger <email@hidden>
- Date: Thu, 3 Dec 2009 10:25:21 +0200
Hello,
I'm making little cocoa application. After the application will be closed i
need to show alert. So i created applicationShouldTerminate delegate:
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app {
if (textChanged == 1)
{
int ret = NSRunAlertPanel(@"Save the work?", @"Do you want save the work?",
@"Yes", @"Cancel", @"No" ) ;
if (ret == NSAlertDefaultReturn)
{
if (save == 0)
{
NSSavePanel *saveDlg = [NSSavePanel savePanel] ;
if ([saveDlg runModal] == NSOKButton)
{
NSString *filename = [saveDlg filename] ;
save = 1 ;
NSString *saveFileName = filename ;
NSError *error;
NSString *text = [[textView textStorage] string] ;
BOOL ok = [text writeToFile:saveFileName atomically:YES
encoding:NSUnicodeStringEncoding error:&error];
if (!ok)
{
NSRunAlertPanel(@"File haven't saved", @"File haven't saved", @"OK", nil,
nil) ;
NSLog(@"Can't save file %@", saveFileName) ;
}
}
}
return NSTerminateNow ;
}
if (ret == NSAlertAlternateReturn)
{
return NSTerminateCancel ;
}
if (ret == NSAlertOtherReturn)
{
return NSTerminateNow ;
}
}
return NSTerminateNow ;
}
I used Interface Builder to delegate NSApplication with my delegate
controller. But don't see any results. But i investigated if i'm also add
this delegate method:
-(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication
*)theApplication
{
return YES;
}
So applicationShouldTerminate is called. But i'm still have problem because
then NSAlert is shown(i don't see my application window, it hides) and if i
press Cancel button NSAlert still shown again. I want to see my application
window then i see NSAlert and Cancel NSAlert button is needed to to work
correctly.
_______________________________________________
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