Re: Running window as a sheet
Re: Running window as a sheet
- Subject: Re: Running window as a sheet
- From: Ken Thomases <email@hidden>
- Date: Mon, 09 Feb 2015 21:24:53 -0600
On Feb 9, 2015, at 9:08 PM, Charles Jenkins <email@hidden> wrote:
> So I have a window that now works fine as a modal window, but because I don’t like where it appears on the screen, I’m attempting to run it as a sheet instead. My Cocoa books and the NSWindow documentation seem to suggest that any window can be run as a sheet, and they along with XCode’s code-completion suggestions guided me to create this code:
>
> -(IBAction)exportToOpenXml:(id)sender
> {
> if ( self.openXmlExportSettings == nil ) {
> self.openXmlExportSettings = [[OpenXmlExportSettings alloc] init];
> }
>
> OpenXmlExportSettings* settings = self.openXmlExportSettings;
> NSWindow* window = [self documentWindow];
> [NSApp beginSheetModalForWindow:window
> completionHandler:^(NSModalResponse returnCode) {
> // Get this sheet offscreen to prepare for upcoming savePanel sheet
> [NSApp orderOut:settings];
> if ( returnCode == NSModalResponseOK ) {
> // Rather than reading out the individual settings here,
> // I’ll just pass along the whole dialog to the next stage,
> // which is in another function in order to avoid
> // such extreme indentation
> [self exportToOpenXmlWithSettings:settings];
> }
> }];
> }
> 2015-02-09 21:39:40.378 MyApp[5572:1677308] An uncaught exception was raised
> 2015-02-09 21:39:40.378 MyApp[5572:1677308] -[NSApplication beginSheetModalForWindow:completionHandler:]: unrecognized selector sent to instance 0x6000001001b0
>
> Looks to me like beginSheetModalForWindow:completionHandler: is the modern API, so why would it be unrecognized? Is there a better way I should be doing this?
The modern API is -[NSWindow beginSheet:completionHandler:]. So, you want to do [window beginSheet:settings.window completionHandler:...]. If you use the modern array, you don't have to order sheets out manually, since they are queued.
To run a sheet requires that you specify two windows: 1) the window to be the sheet, and 2) the window to host the sheet (or to which the sheet is attached). There's no way that [NSApp beginSheetModalForWindow:window completionHandler:...] could work, because you're only specifying one window. The deprecated way, which was a method on NSApplication, was -beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo: and it does take two windows.
-beginSheetModalForWindow:completionHandler: is a method on NSAlert and NSSavePanel. The receiver is the window to act as the sheet. The first parameter is the window to host the sheet. It's not appropriate for your case because your sheet window is not an NSAlert or NSSavePanel.
Regards,
Ken
_______________________________________________
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