Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MayPeng

macrumors member
Original poster
Nov 21, 2010
53
0
I create a cocoa application, as we know it run a default window if we don't add any code. Now I want open a file dialog before the main window display.
ps. I open file dialog using method as the following:
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
if([openPanel runModalStyle:nil] == NSOKButton)
{
//deal the data in the opening file
}
But I couldn't put this code onto right place. Where should I put it in order to reach my aim?
 
Not sure why you need to do this, but here goes.

If you are using Snow Leopard, you already have the app delegate in XCode, you could put the code in the delegate method windowWillOpen. You will probably need to make sure that the file dialog is only opened at startup, and not every time, the user creates a new window, if you are using multiple documents. Maybe completely wrong.
 
I'd suggest unchecking the "visible on launch" checkbox for the main window, then running the open dialog in the applicationDidFinishLaunching implementation of your app delegate.

Then, once you're done with the dialog, bring the main window to the foreground manually -- if you actually still want it to appear, that is.
 
I'd suggest unchecking the "visible on launch" checkbox for the main window, then running the open dialog in the applicationDidFinishLaunching implementation of your app delegate.

Then, once you're done with the dialog, bring the main window to the foreground manually -- if you actually still want it to appear, that is.

You are right.I indeed will bring the main window once done with the dialog.
Now I have dealed with the problem according to what you said.I very very appreciate you!!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.