views:

121

answers:

2

Hi....

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.

A: 

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.
Laurent Etiemble
Ya...I got you...But i guess its just a work around.I guess their is should be some simple way of doing it........When in windows we can pop up a message box so easily..y it would be so tough here.....Please reply soon..Thanks for the reply....
Pradeep Kumar
My guess is that the modal dialog can only be prompted it the main runloop is started, and this is done when invoking the NSApplicationMain function (http://developer.apple.com/mac/library/documentation/cocoa/reference/ApplicationKit/Miscellaneous/AppKit_Functions/Reference/reference.html#//apple_ref/c/func/NSApplicationMain). And as this function load the main NIB, I don't see any other solution.
Laurent Etiemble
You are very correct...its not possible to create a modal dialog from a thread or before launching the main window.....But im not able to give any message boxes before the main window is launched.......
Pradeep Kumar
You can control when the main window is displayed. The NSApplicationDidFinishLaunchingNotification gives you the perfect time to show your modal box and then decide to show your main window.
Laurent Etiemble
+3  A: 

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.

Peter Hosey