• 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: Peter Sichel <email@hidden>
  • Date: Tue, 25 Sep 2001 10:28:45 -0400

Thanks for the response.

At 12:38 PM -0300 9/24/01, Rainer Brockerhoff wrote:
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.

You were right about that.

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

I tried that, but it also seems to come back nil (I made sure
I connected it using IB).


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.

This led me to the following experiment:

- (IBAction)showWindow:(id)sender
{
pingWindowController = [[PingWindowController alloc]
initWithWindowNibName:@"Ping" owner:sender];
if (pingWindowController) {
NSWindow *myWindow = [pingWindowController window];
if (myWindow == nil) NSLog(@"Window is nil (before)");
[myWindow makeKeyAndOrderFront:sender];
myWindow = [pingWindowController window];
if (myWindow == nil) NSLog(@"Window is nil (after)");
}
}

NSLog shows that myWindow is nil both before and after,
yet the window appears as a non-key window when I do
[myWindow makeKeyAndOrderFront:sender]

What's going on here?

If I change the code slightly to use a windowOutlet like this:

NSWindow* myWindow = [pingWindowController windowOutlet];
if (myWindow == nil) NSLog(@"Window is nil (before)");
[myWindow makeKeyAndOrderFront:sender];

The window never appears.
And like this:

NSWindow* myWindow;
[pingWindowController window]; // connect outlet
myWindow = [pingWindowController windowOutlet];
if (myWindow == nil) NSLog(@"Window is nil (before)");
[myWindow makeKeyAndOrderFront:sender];

The window does appear, but is not key.


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.

As above, I tried this and believe the windowOutlet was connected
since makeKeyAndOrderFront displays the window, but it's still not key.

There must be a way to do this since choosing the
window name in the Window menu works. Any ideas?

Thanks again for trying.

- Peter
--


References: 
 >Re: Loading a nib window and making it key (From: Rainer Brockerhoff <email@hidden>)

  • Prev by Date: releasing NSArrays, NSDictionaries, etc ??
  • Next by Date: Re: TableView and context menus
  • 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