• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Loading a nib window and making it key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading a nib window and making it key


  • Subject: Re: Loading a nib window and making it key
  • From: Rainer Brockerhoff <email@hidden>
  • Date: Mon, 24 Sep 2001 12:38:28 -0300

>Date: Mon, 24 Sep 2001 09:42:26 -0400
>From: Peter Sichel <email@hidden>
>
>I'm loading a window from a nib file and would like it to
>appear as the key window so the user can begin typing immediately.
>I think I'm using standard techniques:
>
>I've subclassed NSWindowController and include the following init
>
> self = [super initWithWindowNibName:@"Ping"];
>
> From the caller I do
>
> pingWindowController = [[PingWindowController alloc] init];
> if (pingWindowController) {
> [pingWindowController showWindow:sender];
> if (![[pingWindowController window] isKeyWindow]) NSLog(@"Not
>key window!");
> }
>
>The window appears but is not made the key window until
>I click in it, or select the corresponding name
>from the Window menu.
>
>The documentation for showWindow (NSWindowController)
>or makeKeyAndOrderFront (NSWindow) claim they will make
>the window key, but there is obviously some undocumented
>dependency because that's not happening. I'm not sure
>how to figure out what this might be since I can't see
>the sources and the documentation has no such reference.

Not exactly the same case, but I use the following technique to open a generic window from somewhere (usually a menu command):

[[[NSWindowController alloc] // allocate
initWithWindowNibName:@"TheNib" // nib name
owner:self] // or whatever
window]; // this last connects the outlet
// windowOutlet points at the window
[windowOutlet makeKeyAndOrderFront:self]; // make key window

The problem with your code probably will be that [pingWindowController window] in the last line always returns nil, so NSLog is always called.

I found the way that works is to create an outlet pointing at the window, rather than use -[NSController window].

Another funny thing is that outlets aren't connected by -[NSController initWithWindowNibName]. If you call -[NSController showWindow], the outlets are connected but the window is shown immediately, which isn't always desired.

Call -[NSController window] and throw the (nil) result away to connect the outlets without showing the window; you can then move the window around (for instance) before calling makeKeyAndOrderFront.

Hope this helps,

--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://www.brockerhoff.net/ (updated July 2000)


  • Follow-Ups:
    • Re: Loading a nib window and making it key
      • From: Peter Sichel <email@hidden>
    • Re: Loading a nib window and making it key
      • From: Peter Sichel <email@hidden>
  • Prev by Date: Re: Is there a decent Obj-C for Windows?
  • Next by Date: Re: Is there a decent Obj-C for Windows?
  • Previous by thread: Re: Loading a nib window and making it key
  • Next by thread: Re: Loading a nib window and making it key
  • Index(es):
    • Date
    • Thread