• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fwd: applicationShouldTerminate problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: applicationShouldTerminate problem
      • From: Jens Alfke <email@hidden>
    • Re: applicationShouldTerminate problem
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: Re: Best way to hook into the run loop?
  • Next by Date: Why is "set" a class method of NSColor?
  • Previous by thread: Re: Best way to hook into the run loop?
  • Next by thread: Re: applicationShouldTerminate problem
  • Index(es):
    • Date
    • Thread