macos – 在Swift中打开新窗口

我试图在我的Swift应用程序中打开一个新窗口,但我无法打开它.
class AppDelegate: NSObject,NSApplicationDelegate 
{
    func applicationDidFinishLaunching(aNotification: NSNotification)
    {
        openMyWindow()
    }

    func openMyWindow()
    {
        if let storyboard = nsstoryboard(name: "Main",bundle: nil)
        {
            if let vc = storyboard.instantiateControllerWithIdentifier("MyList") as? MyListViewController
            {
                var myWindow = NSWindow(contentViewController: vc)
                myWindow.makeKeyAndOrderFront(self)
                let controller = NSWindowController(window: myWindow)

                controller.showWindow(self)

            }
        }
    }
}

我在IB中设置了Storyboard ID.

我已经跟踪了代码,它确实进入窗口打开代码,但它没有做任何事情.

顺便说一句,我确实有一个认的故事板入口点设置,认窗口打开确定但我需要打开第二个窗口,这是不起作用的.

执行openMyWindow()方法后,windowController将被释放,因此窗口为零.这就是它不存在的原因.

您必须在您的班级中保持窗口以使其保持活动状态,然后窗口将可见.

var windowController : NSWindowController?

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...