[英]How can I update my Window via AppDelegate in macOS Cocoa?
I am using ViewController for my app content, I want be able to update my app window in AppDelegate.我正在为我的应用程序内容使用 ViewController,我希望能够在 AppDelegate 中更新我的应用程序 window。 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.
我知道我可以从 ViewController 更新我的 window 但对于这个问题我想从 AppDelegate 更新我的 window 而 ViewController 将负责我的应用程序的内容。
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;为你的视图添加声明 controller,然后将其添加到 window; (example)
(例子)
var myVC = aViewController()
inside applicationDidFinishLaunching;在 applicationDidFinishLaunching 里面;
window?.contentView?.addSubview(aVC.view)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.