简体   繁体   English

如何在 macOS Cocoa 中通过 AppDelegate 更新我的 Window?

[英]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.

相关问题 如何通过操作更新 macOS Storyboard Cocoa 项目的 Window 标题? - How can I update my Window title for macOS Storyboard Cocoa project via an action? 如何使用 Cocoa 在 Swift 中打开 macOS 中的另一个窗口 - How do I open another window in macOS in Swift with Cocoa 如何将 Xcode 更新到 11.0,目前我使用的是 macOS High Sierra(版本 10.13.6),我无法更新我的 macOS - How to update Xcode to 11.0, currently I am using macOS High Sierra (version 10.13.6), I can't update my macOS Cocoa Mac:从AppDelegate创建窗口 - Cocoa Mac : creating window from AppDelegate 可可窗口没有显示在macOS Sierra上 - Cocoa Window Not Showing on macOS Sierra 如何为 (UIApplication.shared.delegate as! AppDelegate).window 中视图的所有子视图设置辅助功能标识符? - How can I set Accessibility Identifier for all the subviews of a view in (UIApplication.shared.delegate as! AppDelegate).window? 如何在 macOS (SwiftUI) 中的 window 按钮周围添加填充? - How can I add padding around the window buttons in macOS (SwiftUI)? 如何使用 Cocoa 在我的 Dock 图标上添加徽章? - How I can add a badge on my Dock icon using Cocoa? 如何让我的 window 从另一个被拖到 MacOS 上的 window 窃取焦点? - How do I make my window steal focus from another window being dragged on MacOS? 如何添加一个从我的appdelegate类中迅速调用的弹出窗口? - how can i add a popup that is invoked from my appdelegate class in swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM