I'm trying to write the programmatic equivalent of a nib file I've setup that contains two windows: a main window and sheet that appears after launch to prompt for credentials. Wiring these up in IB works fine, so long as one remembers to uncheck the "Visible at Launch" box on the sheet/window.
However I can't figure out what the API equivalent is of "Visible at launch". When I run my app using the programmatic version the sheet is detached and not the key view in the same way my app ran with the nib when "Visible at Launch" was checked. So my assumption, then, is that I'm missing the secret visible-at-launch sauce.
Does anyone know how to do this?
P.S. I know how to make this work in IB, I specifically want to figure out the code equivalent so please don't tell me to just use the nib. I know that.
NSWindows are typically created hidden. So you shouldn't have to do anything; just don't show the window until you need it. Here's a simple example.
NSWindow *sheetWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO];
NSTextField *field = [[NSTextField alloc] initWithFrame: NSMakeRect(25, 25, 50, 50)];
[[sheetWindow contentView] addSubview:field];
[NSApp beginSheet:sheetWindow modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(sheetDidEnd:) contextInfo:NULL];
The text field obtained keyboard focus when I ran the above.
In future, please provide code in cases like this—it's a lot easier to correct existing code than to write new code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With