Re: problems with NSBeginAlertSheet
Re: problems with NSBeginAlertSheet
- Subject: Re: problems with NSBeginAlertSheet
- From: Eric Peyton <email@hidden>
- Date: Thu, 17 May 2001 22:28:43 -0500
On Thursday, May 17, 2001, at 05:44 PM, email@hidden wrote:
hello everyone. i am having problems with NSBeginAlertSheet.
here's the header for it..
APPKIT_EXTERN void NSBeginAlertSheet(NSString *title, NSString
*defaultButton, NSString *alternateButton, NSString *otherButton,
NSWindow *docWindow, id modalDelegate, SEL didEndSelector, SEL
didDismissSelector, void *contextInfo, NSString *msg, ...);
now, i want to have a standard dialog here, when the user presses
'ok' i want the sheet to call a method, and when the user presses
'cancel' i want the sheet to go away without doing anything. seems
simple enough. well, i can get the sheet to display, and i can
even get the sheet to call the method i want. but.. instead of the
method getting called only when a certain button is pushed on the
sheet, it is ALWAYS called after the sheet has gone away. rather
annoying. here is an example of the usage i've been using (called
from my Controller object):
NSBeginAlertSheet(@"Alert", @"OK", @"Cancel", NULL, [self window],
self, @selector(start), NULL, NULL, @"Press ok or cancel");
now, i have tried using all three possible buttons ( in the
definition above: *defaultButton, *alternateButton, and
*otherButton) with no success. i have also tried putting the
selector in both the *didEndSelector position and the
*didDismissSelector position, both with no luck, the method is
called no matter what button is pushed. i have tried putting a
selector in both places (in case it didn't like have one being
NULL), still no luck.
i can not for the life of me figure out why the sheet is calling
the method regardless of which button is pushed.
is anyone else having this problem?
You are probably having the problem because you are using the SEL
didEndSelector incorrectly. If you look at the documentation you
need a selector of the form
@selector(sheetDidEnd:returnCode:contextInfo:)
NSBeginAlertSheet(@"Alert", @"OK", @"Cancel", NULL, [self window],
self, @selector(sheetDidEnd:returnCode:contextInfo:), NULL, NULL,
@"Press ok or cancel");
And then add this method to your class
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode
contextInfo:(void *)contextInfo
{
if (returnCode == 0) // button OK was pressed
[self start];
else // something else was pressed
[self stop]; // or nothing
}
I believe that this is pretty well spelled out in the headers and
the documentation, but it can be confusing at first.
Eric
any help would be greatly appriciated.
Jason Moore
email@hidden
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev