4

NSPanelのみを含むxibファイルがあります。このパネルをモーダルシート(with beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:)として表示しようとしています。このxibのファイルの所有者は、NSPanelへのIBOutletを持つコントローラークラス「MyController」です。

私が探しているのは次のようなものです。

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

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

質問:MyControllerはまたはから継承する必要がありますNSWindowControllerNSObject?試しNSWindowControllerてみましたが、いつもinitWithWindowNibName:への出口はありません。NSPanel

ありがとう

4

1 に答える 1

8

私はそれを解決します。シートに使用しているウィンドウオブジェクト(IB内)のほとんどすべてのプロパティを非アクティブ化する必要があります。シートを表示するために、コントローラーに次のメソッドを追加します。

- (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シートウィンドウへのIBOutletです。

JonHessとJWWalkerにご協力いただきありがとうございます

于 2010-11-28T20:00:33.227 に答える