Re: NSBeginAlertSheet not waiting for button to be pushed
Chad Leigh -- ObjectWerks Inc <chad+macosx-AU1NHruoRJaEK/[email protected]>
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
On Feb 7, 2010, at 5:02 PM, Christiaan Hofman wrote: > > On Feb 7, 2010, at 7:41, Chad Leigh -- ObjectWerks Inc wrote: > >> Hi >> >> I am having an issue with NSBeginAlertSheet() on 10.6. (Don't know how or if it works or not on 10.5 with this iteration -- this app is in production with slightly different code on 10.5 without issue) >> >> The code below lives in an object that sends a remote host a transaction and if the transaction returns an error it runs this Alert Sheet and previously (in the production code) the window passed in was [self mainWindow] which was a reference to the main app window. I am now calling this object to do a transaction during a registration sequence and the window up is an auxiliary panel that captures registration info. So I changed the window to be generically [NSApp keyWindow] as my thinking is that this should always use the correct window. >> >> Now, when it is called it does in fact put the alert sheet up on the panel. But the function ends immediately and does not wait for the user to hit OK. > > Actually, that particular aspect is exactly what it is supposed to do. Notice that the function has "Begin" in the name, not "Run" as the alert panel functions do. I don't think so. For one, everywhere else it runs the sheet and if you read the Apple docs it says that it creates and runs the sheet NSBeginAlertSheet Creates and runs an alert sheet. void NSBeginAlertSheet ( NSString *title, NSString *defaultButton, NSString *alternateButton, NSString *otherButton, NSWindow *docWindow, id modalDelegate, SEL didEndSelector, SEL didDismissSelector, void *contextInfo, NSString *msg, ... ); Discussion Creates and runs an alert sheet on docWindow, with the title of title, the text of msg, and buttons with titles ofdefaultButton, alternateButton, and otherButton. The buttons are laid out on the lower-right corner of the sheet, with defaultButton on the right, alternateButton on the left, and otherButton in the middle. If title is nil or an empty string, a default localized title is used (“Alert” in English). If defaultButton is nil or an empty string, a default localized button title (“OK” in English) is used. For the remaining buttons, this function creates them only if their corresponding button title is non-nil. A Command-D key equivalent for the “Don’t Save” button is provided, if one is found. The button titles are searched for the localized value for “Don’t Save.” If a match is found, that button is assigned a Command-D key equivalent, provided it is not the default button. If you create a modal panel using runModalForWindow: orbeginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:, you can assign the key equivalent yourself, using setKeyEquivalent: and setKeyEquivalentModifierMask:. The msg argument is the message that’s displayed in the panel. It can use printf-style formatting characters; any necessary arguments should be listed at the end of the function’s argument list (after the msg argument). For more information on formatting characters, see the man page for printf. When the modal session is ended, and before the sheet is dismissed, the didEndSelector is invoked on themodalDelegate. passing contextInfo. After the sheet is dismissed, the didDismissSelector is invoked on themodalDelegate, passing contextInfo. Typically, you will want to implement the didEndSelector but you may passNULL for the didDismissSelector. The two selectors should be defined as follows: sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo; sheetDidDismiss:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo; where sheet is the alert sheet, returnCode specifies which button the user pressed, and contextInfo is the samecontextInfo passed into NSBeginAlertSheet. returnCode can be one of the following: NSAlertDefaultReturn means the user pressed the default button. NSAlertAlternateReturn means the user pressed the alternate button. NSAlertOtherReturn means the user pressed the other button. NSAlertErrorReturn means an error occurred while running the alert panel. Availability Available in Mac OS X v10.0 and later. Related Sample Code CameraBrowser ImageClient QTKitPlayer Quartz Composer WWDC 2005 TextEdit ScannerBrowser Declared In NSPanel.h > > Christiaan > >> This is true with "nil" passed in for the did-end selector or a selector being passed in. If I pass a selector in, that selector is not called. > >> Any ideas? >> >> Thanks >> Chad >> >> >> NSBeginAlertSheet( >> [reply objectForKey:@"errorMessage"], >> // sheet message >> @"OK", // default button label >> nil, // no third button >> nil, //no other button label >> [NSApp keyWindow], // window sheet is attached to >> self, // we will be our own delegate >> @selector(sheetDidEnd:returnCode:contextInfo:), >> // did-end selector >> NULL, // no need for did-dismiss selector >> nil, // context info >> [NSString stringWithFormat:@"message with code %@", [reply objectForKey:@"errorCode"]]); >> // additional text >> > _______________________________________________ > MacOSX-dev mailing list > [email protected] > http://www.omnigroup.com/mailman/listinfo/macosx-dev