0
votes

Maybe I'm missing something really simple here (I hope so), but is there a trick to changing the title of an NSPanel at runtime? The obvious [panel setTitle:@"New title"] doesn't seem to be working.

I'm trying to display a regular panel which contains a WebView, and I want to the title of the panel to reflect the title of the HTML content.

I subclassed NSWindowController and called initWithWindowNibName. I changed the class in the nib from NSWindow to NSPanel, and everything seems to be working okay. In my window controller, I did this:

- (void)windowDidLoad {
    [super windowDidLoad];
    [[self window] setTitle:@"My New Title"];
}

(I will actually be setting the title in a webView:didReceiveTitle:forFrame delegate, but this is simpler to show).

I verified that the code is getting called, and there are no errors reported, but the title never changes. Any ideas?

2

2 Answers

4
votes

In the nib file that contains the panel, make sure that the File’s Owner’s class has been set to your NSWindowController subclass and that the window outlet from File’s Owner has been connected to the panel. Otherwise, the window controller won’t know which window it should be managing and [self window] returns nil.

0
votes

You're setting the title, but you're not telling the window to display itself again.