zoukankan      html  css  js  c++  java
  • Swift-打开其它Storyboard中的自定义模态窗口

    本文的方法针对OS X应用开发。

    如果想在某个ViewController中,用模态窗口的方式,打开某个Storyboard中定义的WindowController。可用以下方式。

    let story = NSStoryboard(name: "DebugStoryboard", bundle: nil)

    let ctl = story.instantiateInitialController() as! NSWindowController

    NSApp.runModalForWindow(ctl.window!)

    其中,DebugStoryboard是Storyboard对应的文件名。

    这种方式,需要在模态窗口关闭时,解除模态状态,否则,程序会假死,不能响应任何的点击动作。

    要解除Modal状态,自定义窗口的contentViewController需要继承NSWindowDelegate协议,然后在viewDidDisappear()方法中加入NSApp.stopModal()这一句。

    class DebugViewController: NSTabViewController,NSWindowDelegate {

     

      override func viewDidLoad() {

        super.viewDidLoad()

        // Do view setup here.

      }

      

      override func viewDidDisappear() {

        //窗口关闭时,解绑Modal状态,否则APP假死

        NSApp.stopModal()

     

      }

     

     

    }

  • 相关阅读:
    Navicat for SQLite之外键(05)
    UIButton
    多线程中的API
    UIImageView
    IOS中实现单例
    IOS中的多线程【二】— NSOperation和NSOperationQueue
    IOS中的多线程
    OC中新增的数据类型
    【转】c# DBF数据库导入导出实例
    【经验】学习新知识的经验
  • 原文地址:https://www.cnblogs.com/tt2015-sz/p/5035463.html
Copyright © 2011-2022 走看看