tags:

views:

159

answers:

2

I want to show a splash Screen before the App lunch. First I make the SplashWindow subclassing the NSWindow, the code is :

- (id)initWithContentRect(NSRect)contentRect 
styleMask(unsigned int)aStyle 
backing(NSBackingStoreType)bufferingType 
defer(BOOL)flag {

self = [super initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; 
[self setBackgroundColor: 
[NSColor clearColor]]; 
[self setLevel: NSStatusWindowLevel]; 
[self setAlphaValue:1.0]; 
[self setOpaque:NO]; 
[self setHasShadow: YES]; 
return self;

}

and then in the awake from nib in the main app controller:

loadWindow = [[NSWindow alloc] initWithContentRect:[loadWindow frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]; 
[loadWindow setContentView:theView]; 
[loadWindow setHasShadow:YES]; [
loadWindow setLevel:NSStatusWindowLevel]; 
[loadWindow makeKeyAndOrderFront:self];

and then I let the loadWindow closed after 3 secondes, I used the method [loadWindow orderOut:self], but when the splash window closed , the mainwinow didn't show . what am I missing? My App is a multi_Documents . and in the mainMenu.nib there was one window(loadwindow),in IB I have connected up the loadWindow outlet in the main controller. I have also connected the view and image. and I changed another way : in the delegate method:applicationWillFinishLaunching: I orderFront the loadWindow , in the method:applicationDidFinishLaunching: I orderOut the loadWindow after 3 seconds, but the mainWindow didn't show too.Somebody can give some advice or codes the result the problem? Thank you very much!

A: 

I don't see anything that would make another window show in the code you posted. Why don't you try sending your main window makeKeyAndOrderFront:?

Chuck
+2  A: 

Answer to title: Because your app isn't running yet. An application that isn't running can't do anything.

Serious answer to question:

First, you don't need to subclass NSWindow.

Second, you aren't instantiating your subclass, you're instantiating NSWindow. That's why you're not getting your subclass's behavior. (And this is what you should be doing, since you don't need the subclass.)

Third, you're trying to ask a window that doesn't exist yet for the frame you'll use to create it. loadWindow is nil until after you create something and store it there.

Fourth, because you are asking nil for its frame, you are getting a garbage rectangle back. Then you create a window with this garbage rectangle. Unsurprisingly, when you put this window on the screen, it appears in a random position (probably off-screen) with a random size (probably either too large to create or negative).

Fifth, what makes you think that telling a window to order out would cause some other window to order in? How is it supposed to know what window to order in?

Leaving aside the undeniable reality that the very existence of a splash screen punishes the user for using your application, you should be using NSWindowController to load the window and to do your set-up such as setBackgroundColor: and setLevel:. And in your timer method, where you order out the splash window, you must also explicitly order in the main window.

Peter Hosey