开发者

NSWindow created in IB won't show modally in the application

开发者 https://www.devze.com 2023-01-21 22:15 出处:网络
I have an application that when pressing a button it should show a modal window. I have some questions about it but I\'m going to narrow it to what it\'s giving me a headache.

I have an application that when pressing a button it should show a modal window. I have some questions about it but I'm going to narrow it to what it's giving me a headache.

I want to add that I'm already doing something alike that when applied to this particularly case won't work. What I already do is to show modally a NSOpenPanel. This is the code for it.

This code is inside the 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];
}
开发者_开发百科

Now What I'm trying to do and that won't work

I created a xib file that has a HUD Window (how it's named in IB) that acts like a NSPanel. I created a windowcotroller that listen to a button (testButton). Here's the code:

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

I set the file's owner of the xib file to be of the class BrowserWindowController and linked the button with the testbutton.

Back to the appDelegate when a button is clicked I want to show this Panel modally. Here's the code:

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

I don't see any function in the API like NSOpenPanel to show this window modally.

Thx to anyone who might answer.


The reason there is no NSWindow API for running modally is because it's the application that is going into a modal mode. See How Modal Windows Work and Introduction to Sheets.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号