Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Modal Dialog or Window in Cocoa Objective-C?

Tags:

objective-c

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.

I can create a custom window in a nib file and load the custom dialog on button click, but it's not a modal dialog. I can switch back to the main window.

MyWindowController is the NSWindowController subclass. I used the code below to display my window in response to the button event:

MyWindowController *pController = [[MyWindowController alloc] 
                                   initWithWindowNibName:@"nibfilename"];
[MyWindowController showWindow:self];
like image 795
Pradeep Kumar Avatar asked Dec 14 '09 18:12

Pradeep Kumar


1 Answers

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.

like image 178
Chuck Avatar answered Sep 21 '22 15:09

Chuck