1

ボタンを押すとモーダルウィンドウが表示されるアプリケーションがあります。それについていくつか質問がありますが、頭痛の種に絞り込みます。

私は、この特定のケースに適用するとうまくいかないようなことをすでに行っていることを付け加えたいと思います。私がすでに行っていることは、NSOpenPanel をモーダルに表示することです。これがそのコードです。

このコードは appDelegate 内にあります。

-(IBAction) respondToPublishAction:(id) sender {
    NSArray *fileTypes = [NSArray arrayWithObjects:@"xml", @"txt", nil];

    NSOpenPanel *oPanel = [NSOpenPanel openPanel];

    NSString *startingDir = [[NSUserDefaults standardUserDefaults] objectForKey:@"StartingDirectory"];

    if (!startingDir)
        startingDir = NSHomeDirectory();

//Setting the attributes
[oPanel setAllowsMultipleSelection:NO];
[oPanel setTitle:@"XML file for publishing services"];
[oPanel beginSheetForDirectory:startingDir file:nil types:fileTypes
                modalForWindow:[self window] modalDelegate:self
                didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
                   contextInfo:nil];
}

今私がやろうとしていることとそれがうまくいかないこと

NSPanel のように機能する HUD ウィンドウ (IB での名前の付け方) を持つ xib ファイルを作成しました。ボタン (testButton) をリッスンする windowcotroller を作成しました。コードは次のとおりです。

@interface BrowserWindowController : NSWindowController {
}
-(IBAction) testButton:(id) sender;
@end

xib ファイルのファイル所有者を BrowserWindowController クラスに設定し、ボタンを testbutton にリンクしました。

ボタンがクリックされたときに appDelegate に戻る このパネルをモーダルに表示したい。コードは次のとおりです。

- (IBAction) respondToBrowseAction:(id) sender {
browsePanel = [[BrowserWindowController alloc] initWithWindowNibName:@"BroserWindow"];
}

このウィンドウをモーダルに表示するための NSOpenPanel のような関数が API にありません。

答えるかもしれない人へのThx。

4

1 に答える 1

0

モーダル モードで実行するための NSWindow API がない理由は、アプリケーションがモーダル モードになるためです。モーダル ウィンドウのしくみシートの概要を参照してください。

于 2010-10-27T01:32:56.797 に答える