Re: returnCode from beginSheetModalForWindow is incorrect?
Re: returnCode from beginSheetModalForWindow is incorrect?
- Subject: Re: returnCode from beginSheetModalForWindow is incorrect?
- From: "Geert B. Clemmensen" <email@hidden>
- Date: Fri, 18 Mar 2005 11:58:22 +0100
On 18. mar 2005, at 11.14, Jeremy Dronfield wrote:
On 17 Mar 2005, at 10:54 am, Geert B. Clemmensen wrote:
The returnCode value should supposedly refer to the documentation for NSAlert, but it doesn't.
Yes it does. Previously I've mostly used -[NSAlert runModal] which returns the correct return codes defined in NSAlert. So I just tested it with -beginSheet... like so:
- (void)runWarning
{
NSAlert *warningAlert = [[[NSAlert alloc] init] autorelease];
[warningAlert addButtonWithTitle:@"Go Ahead"];
[warningAlert addButtonWithTitle:@"Cancel"];
[warningAlert setMessageText:@"Do something with the selected files?"];
[warningAlert setInformativeText:@"(You can switch off this warning in Preferences)"];
[warningAlert setAlertStyle:NSWarningAlertStyle];
[warningAlert beginSheetModalForWindow:myWindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
}
- (void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
NSLog(@"returnCode:%d", returnCode);
[[alert window] orderOut:nil];
}
The log output:
2005-03-18 09:56:51.752 AnApp [471] returnCode:1000 << clicked "Go Ahead"
2005-03-18 09:56:56.684 AnApp [471] returnCode:1001 << clicked "Cancel"
Exactly as defined in NSAlert.h and described in the NSAlert documentation. Where's the problem?
Well, you example works as supposed, which you also have demonstrated, BUT if you create the warningAlert like this:
NSAlert* warningAlert = [NSAlert alertWithMessageText:@"Do something with the selected files?"
defaultButton:@"Go Ahead"
alternateButton:@"Cancel"
otherButton:nil
informativeTextWithFormat:@"(You can switch off this warning in Preferences)"];
You get:
2005-03-18 11:53:22.677 XYZ[2421] returnCode:1
2005-03-18 11:53:27.326 XYZ[2421] returnCode:0
I guess the explanation is to be found in this statement in the description for the alertWithMessage: method:
This is a compatibility method. It is designed for easy adoption by applications migrating from the corresponding functional API.
Regards,
Geert
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden