I have a Cocoa application with a secondary window created using a subclass of NSWindowController. I wish to set the window title. The documented method call is setTitle:. I have called this from within the window controller as follows:
- (void)windowDidLoad
{
// set window title
[[self window] setTitle:@"test string"];
}
This does not affect the title of the window though.
Any suggestions please?
I just use
self.window?.title = "Some String"
where I create the window.
You can connect Your window with IBOutlet and then change Your code:
[[self window] setTitle:@"test string"];
To this:
[yourWindow setTitle:@"test string"];
Full code for example:
.h
IBOutlet NSWindow *yourWindow; //Don't forget to connect window to this
.m
-(void)awakeFromNib {
[yourWindow setTitle:@"test string"];
}
Title can be changed in Attributes inspector:
The NSWindowController class reference indicates that to customize the title, you should override the windowTitleForDocumentDisplayName:
method.
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