views:

18

answers:

1

Hi,

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.

A: 

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.

Nathan Kinsinger
Why it worked with oPanel then? That's my main missunderstanding
gvalero87
The open panel has a connivence method for creating a window modal sheet. If you want a sheet to show up on an window then look at using sheets.
Nathan Kinsinger