I am using ViewController for my app content, I want be able to update my app window in AppDelegate. I know that I can update my window from ViewController but for this question I want update my window from AppDelegate while ViewController is going take care of content of my app.
import Cocoa
@main
class AppDelegate: NSObject, NSApplicationDelegate {
let window: NSWindow? = NSApp.mainWindow
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
window?.center()
window?.setFrameAutosaveName("Main Window")
window?.title = "changed label"
window?.styleMask.remove(.closable)
window?.styleMask.remove(.fullScreen)
window?.styleMask.remove(.miniaturizable)
window?.makeKeyAndOrderFront(nil)
}
}
Add a declaration for your view controller and then add it to the window; (example)
var myVC = aViewController()
inside applicationDidFinishLaunching;
window?.contentView?.addSubview(aVC.view)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.