加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

macos – 在Swift中打开新窗口

发布时间:2020-12-14 05:48:18 所属栏目:百科 来源:网络整理
导读:我试图在我的Swift应用程序中打开一个新窗口,但我无法打开它. class AppDelegate: NSObject,NSApplicationDelegate { func applicationDidFinishLaunching(aNotification: NSNotification) { openMyWindow() } func openMyWindow() { if let storyboard = NS
我试图在我的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?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读