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 protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]