Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mkristain

macrumors regular
Original poster
Aug 18, 2011
115
0
hi i want to display a alert message when clicked close button of application and if press 'yes' on message application is exit but is 'no' on message application not close.

i am doing this but it not works fine on 'no'

Code:
- (void)windowWillClose:(NSNotification *)aNotification
{
	NSAlert *alert = [NSAlert alertWithMessageText:@"\nDo you really want exit?"
									 defaultButton:@"Yes" alternateButton:NO otherButton:@"No"
						 informativeTextWithFormat:@""];
	
	int result = [alert runModal];
	
	if(result == NSOKButton)
	{
		
		[NSApp terminate:self];
	}
	else
	{
		[[NSNotificationCenter defaultCenter] removeObserver:self];
		//return NSTerminateCancel;
	}

}

thanks.
 
If you want this to happen when the window is about to close use windowShouldClose:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.