I'm trying to programmatically create a NSWindowController and its associated window. To do so, I override the window controller's loadWindow
and create the window controller in my app delegate:
class MainWindowController: NSWindowController {
override func loadWindow() {
print("loadWindow")
self.window = NSWindow(contentRect: NSMakeRect(100, 100, 100, 100), styleMask: [.titled, .resizable, .miniaturizable, .closable], backing: .buffered, defer: false)
}
}
@main
class AppDelegate: NSObject, NSApplicationDelegate {
var mwc: MainWindowController!
func applicationDidFinishLaunching(_ aNotification: Notification) {
self.mwc = MainWindowController(window: nil)
self.mwc.showWindow(nil)
}
}
When I run this, I don't see the window, nor does "loadWindow" get printed to the console so it's not even getting called. Any ideas?
loadWindow
isn't called becausewindowNibName
isnil
. – Willeke