tags:

views:

1256

answers:

2

Hi,

Im new to cocoa development.

I need to create an modal dialog, which is to loaded from a Nib File and should be displayed on a button click in the main window.

Im able to create a custom window in a nib file and was also able to load the custom dialog on button click but it was not a modal dialog.im able to switch back to my main window.

MyWindowController is the nswindowscontroller subclass. i used the below code to display my window in the Button Event:

MyWindowController *pController = [[MyWindowController alloc] 
                                   initWithWindowNibName:@"nibfilename"];
[MyWindowController showWindow:self];

Kindly reply soon..... please let me knw if my requirement is not clear.

Thank You

Pradeep

+2  A: 

There are several ways to do this — and in fact two different kinds of modal dialog in OS X: application-modal and window-modal. Using the wrong one will annoy people. One is a sheet, which is attached to the window that it affects (save dialogs are an example of this). The other is application-modal, which blocks the whole application (open dialogs work this way, since they don't apply to any window that exists yet). Apple's sheet documentation should help get you oriented.

Chuck
A: 

Thank you...

(Example). Create a nib with name "About"

if(pAbtCtrl == nil) pAbtCtrl = [[AboutWindowController alloc] initWithWindowNibName:@"About"];

pAbtWindow = [pAbtCtrl window];

[NSApp runModalForWindow: pAbtWindow];

[NSApp endSheet: pAbtWindow];

[pAbtWindow orderOut: self];

Pradeep Kumar