Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How show sheet loaded from xib? (MacOSx)

I have a xib file with only an NSPanel in it, I'm trying to show this panel as modal sheet (with beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:). The file's owner for this xib is a controller class "MyController" which has the IBOutlet to the NSPanel.

What I am looking for is something like:

...
MyController *controller = [[MyController alloc] init];

[NSApp beginSheet:controller.panel modalForWindow:[NSApp mainWindow] modalDelegate:controller didEndSelector:nil contextInfo:nil];
...

Question: Must MyController inherit from NSWindowController or NSObject?. I tried NSWindowController and initWithWindowNibName: but the outlet to NSPanel always is nil.

Thanks

like image 548
Bruno Berisso Avatar asked Feb 26 '23 21:02

Bruno Berisso


1 Answers

I resolve it. You must deactivate almost all the properties of the window object (in the IB) that you are using for the sheet. I add the following method to my controller to show the sheet:

- (void)showInWindow:(NSWindow *)mainWindow {
    if (!panelSheet)
        [NSBundle loadNibNamed:@"XibName" owner:self];

    [NSApp beginSheet:panelSheet modalForWindow:mainWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
    [NSApp runModalForWindow:panelSheet];   //This call blocks the execution until [NSApp stopModal] is called
    [NSApp endSheet:panelSheet];
    [panelSheet orderOut:self];
}

panelSheet is an IBOutlet to the sheet window.

Thanks Jon Hess and JWWalker for your help

like image 68
Bruno Berisso Avatar answered Mar 08 '23 07:03

Bruno Berisso