In xcode 6.1, how do i programmatically change the title of the window created by storyboard? This project is for OS X. By default, it is "Window". I am using OBJ C.
Code in Swift is
override func viewDidAppear() {
self.view.window?.title = "joe"
}
and in Objective-C it's approximately self.view.window.title = @"joe";
It has to be in the viewDidAppear
because in the viewDidLoad
it's too early.
OT, but to do it via Storyboards it's here:
NSWindow
at all, and you probably should not. –
Gun viewDidAppear
for the primary view controller. –
Gun In the AppDelegate context of Apple's common Objective-C Xcode templates for macOS, you can access your main window handle through the following line of code:
[[[NSApplication sharedApplication] mainWindow] setTitle:@"Your Title"];
Or just use the global constant shorthand for the shared app instance:
[[NSApp mainWindow] setTitle:@"Your Title"];
These examples first retrieve the app's instance and then get hold of it's main window. Note that if the app’s storyboard or NIB file has not yet finished loading, the app is inactive or hidden, the title might not get applied.
The above assumes you have a Main.storyboard with hierarchy Window Controller Scene > Window Controller > Window -- with non-custom Identifier==Automatic and not subclassed this NSWindow.
© 2022 - 2024 — McMap. All rights reserved.