Pradeep Kumar
Pradeep Kumar

Reputation: 420

Creating a parenet less modal dialog or MessageBox or alert Sheets in cocoa?

Issue1: I want to show an alert window or message box before the Main Window of the Application is launched. When im using the NSRunAlertPanel() it is not showing the alert window.It is directly launching the Application's Main Window.

Issue2: I want to create an Modal (login dialog) and message boxes in an thread spanned from the main thread.

Its urgent

So, Kindly reply soon...

Thank You Pradeep.

Upvotes: 1

Views: 1302

Answers (2)

Peter Hosey
Peter Hosey

Reputation: 96333

Issue2: I want to create an Modal (login dialog) and message boxes in an thread spanned from the main thread.

In Cocoa, nearly all UI code must run on the main thread. There are a few limited, well-defined exceptions (e.g., the opt-in threaded drawing introduced in Snow Leopard), but the general rule is to not run UI code on another thread.

Besides, you don't need a thread anyway. It's not like the modal dialog is going to be computationally intensive.

Send NSApp a runModalForWindow: message, passing the dialog. This will run the dialog on the main thread, blocking the rest of your UI. If you don't want to block the UI (and you generally shouldn't), just make it key and order it front, like usual.

Upvotes: 3

Laurent Etiemble
Laurent Etiemble

Reputation: 27889

What you can do is:

  • uncheck the "Visible at launch" option for your main window in Interface Builder.
  • start your application as usual
  • decide whether or not to show the modal dialog
  • invoke "orderFront:" message of the main window.

Upvotes: 0

Related Questions