Macos 在NSDocument'中以模式显示视图;窗户

Macos 在NSDocument'中以模式显示视图;窗户,macos,modal-dialog,swift,nswindow,nsdocument,Macos,Modal Dialog,Swift,Nswindow,Nsdocument,我有一个NSDocument子类,它有自己的xib文件。另外,我还有一个NSViewController子类,它也有自己的xib文件,我想以模态的方式呈现它的视图,就像这个。 问题是,它总是将其显示为一个没有标题栏的单独浮动窗口 我试图呈现的视图包含在该xib文件的窗口中。是的,它是MacOSX10.10。这是密码 @IBAction func didPressEditF(sender: AnyObject) { let controller = ViewControl

我有一个
NSDocument
子类,它有自己的xib文件。另外,我还有一个
NSViewController
子类,它也有自己的xib文件,我想以模态的方式呈现它的视图,就像这个。

问题是,它总是将其显示为一个没有标题栏的单独浮动窗口

我试图呈现的视图包含在该xib文件的窗口中。是的,它是MacOSX10.10。这是密码

    @IBAction func didPressEditF(sender: AnyObject) {
        let controller = ViewController(nibName: "ViewController", bundle: nil)
        let window = self.windowControllers[0].window as NSWindow
        window.beginSheet(controller.view.window, completionHandler: didEndPresentingF)
    }

如果你能帮我使用Objective-C,没关系。

好的。我想出来了

起初。我们需要我们的
ViewController
类的属性,这样它在显示后就不会被释放

var controller: ViewController?
然后我们需要一个返回当前文档窗口的方法。不知何故,
self.windowControllers[0]。作为NSWindow的窗口不起作用

    func window() -> NSWindow {
        let windowControllers = self.windowControllers
        let controller = windowControllers[0] as NSWindowController
        let window = controller.window
        return window
    }
最后,打开“工作表”窗口的代码如下所示:

    @IBAction func didPressEditF(sender: AnyObject) {
        controller = ViewController(nibName: "ViewController", bundle: nil)
        self.window().beginSheet(controller!.view.window, completionHandler: didEndPresentingF)
    }

苹果必须对他们过时的文档做些什么。

好吧。我想出来了

起初。我们需要我们的
ViewController
类的属性,这样它在显示后就不会被释放

var controller: ViewController?
然后我们需要一个返回当前文档窗口的方法。不知何故,
self.windowControllers[0]。作为NSWindow的窗口不起作用

    func window() -> NSWindow {
        let windowControllers = self.windowControllers
        let controller = windowControllers[0] as NSWindowController
        let window = controller.window
        return window
    }
最后,打开“工作表”窗口的代码如下所示:

    @IBAction func didPressEditF(sender: AnyObject) {
        controller = ViewController(nibName: "ViewController", bundle: nil)
        self.window().beginSheet(controller!.view.window, completionHandler: didEndPresentingF)
    }

苹果必须对他们过时的文档做些什么。

好吧。我想出来了

起初。我们需要我们的
ViewController
类的属性,这样它在显示后就不会被释放

var controller: ViewController?
然后我们需要一个返回当前文档窗口的方法。不知何故,
self.windowControllers[0]。作为NSWindow的窗口不起作用

    func window() -> NSWindow {
        let windowControllers = self.windowControllers
        let controller = windowControllers[0] as NSWindowController
        let window = controller.window
        return window
    }
最后,打开“工作表”窗口的代码如下所示:

    @IBAction func didPressEditF(sender: AnyObject) {
        controller = ViewController(nibName: "ViewController", bundle: nil)
        self.window().beginSheet(controller!.view.window, completionHandler: didEndPresentingF)
    }

苹果必须对他们过时的文档做些什么。

好吧。我想出来了

起初。我们需要我们的
ViewController
类的属性,这样它在显示后就不会被释放

var controller: ViewController?
然后我们需要一个返回当前文档窗口的方法。不知何故,
self.windowControllers[0]。作为NSWindow的窗口不起作用

    func window() -> NSWindow {
        let windowControllers = self.windowControllers
        let controller = windowControllers[0] as NSWindowController
        let window = controller.window
        return window
    }
最后,打开“工作表”窗口的代码如下所示:

    @IBAction func didPressEditF(sender: AnyObject) {
        controller = ViewController(nibName: "ViewController", bundle: nil)
        self.window().beginSheet(controller!.view.window, completionHandler: didEndPresentingF)
    }

苹果不得不对他们过时的文档做些什么。

你可以调用windowForSheet,一种NSDocument上的方法,而不是挖掘文档的窗口控制器。例如,self.windowForSheet。

您可以调用windowForSheet,这是NSDocument上的一种方法,而不是深入查看文档的窗口控制器。例如,self.windowForSheet。

您可以调用windowForSheet,这是NSDocument上的一种方法,而不是深入查看文档的窗口控制器。例如,self.windowForSheet。

您可以调用windowForSheet,这是NSDocument上的一种方法,而不是深入查看文档的窗口控制器。例如,纸张的自动窗口