xcode OSX Storyboards - 使用标准转场打开非模态窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24694587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:12:27  来源:igfitidea点击:

OSX Storyboards - Open non-modal window with standard segue

xcodemacosswiftxcode6

提问by mic

I try to show a NSViewControllervia a storyboard segue (OSX). The opening window will be an inspector window, so it should be non-modal.

我尝试NSViewController通过故事板转场 (OSX)显示一个。打开的窗口将是一个检查器窗口,所以它应该是非模态的。

When I create an action segue by Ctrl-dragging from the trigger button to the window controller I am offered the following segue style options:

当我通过按住 Ctrl 键从触发器按钮拖动到窗口控制器来创建动作转场时,我提供了以下转场样式选项:

  • Modal
  • Sheet
  • Popover
  • Custom
  • 模态
  • 床单
  • 弹出框
  • 风俗

The first three options are obviously not appropriate.

前三个选项显然不合适。

I'm sure I could create a custom segue to show the view. This would involve creating a class, implementing some methods and so on.

我确定我可以创建一个自定义 segue 来显示视图。这将涉及创建一个类,实现一些方法等等。

However, since my requirement seems quite basic to me, I wonder if I'm missing something obvious, a simple way to open a non-modal window via canvas.

但是,由于我的要求对我来说似乎很基本,我想知道我是否遗漏了一些明显的东西,这是一种通过画布打开非模态窗口的简单方法。

I'm using XCode6-Beta3.

我正在使用 XCode6-Beta3。

回答by ElmerCat

At least right now (Beta3), a non-modal view needs to have its own window, and there's no simple way to create a segue for that.

至少现在(Beta3),非模态视图需要有自己的窗口,并且没有简单的方法可以为此创建转场。

Instead, drag a new Window Controller object onto your Storyboard. It will come with its own content view as a Relationship Segue. However, if there's a different view you want to use for the window (e.g.: a Tab View Controller), simply delete the new View Controller and control-drag from the new Window Controller to the View Controller whose view you wish to use for the window content.

相反,将一个新的 Window Controller 对象拖到您的 Storyboard 上。它将带有自己的内容视图作为关系转场。但是,如果您想为窗口使用不同的视图(例如:选项卡视图控制器),只需删除新的视图控制器并从新的窗口控制器控制拖动到您希望用于其视图的视图控制器窗口内容。

Important:Select the Window Controller object in the Storyboard, and in the Identity Inspector, set the Storyboard ID to a string that will identify the window (e.g.: "Inspector").

重要提示:在 Storyboard 中选择 Window Controller 对象,然后在 Identity Inspector 中,将 Storyboard ID 设置为将标识窗口的字符串(例如:“Inspector”)。

Then, just write a little code to show the window:

然后,只需编写一些代码来显示窗口:

var inspectorController: NSWindowController?
@IBAction func showInspector(sender : AnyObject) {
    if !inspectorController {
        let storyboard = NSStoryboard(name: "Main", bundle: nil)
        inspectorController = storyboard.instantiateControllerWithIdentifier
           ("Inspector") as? NSWindowController
    }
    if inspectorController { inspectorController!.showWindow(sender) }
}

I actually found it preferable notto use the Main storyboard for any windows at all. One of the reasons is because with Storyboards (at least right now), there's no way of intercepting the initial segue when the application launches, and windowWillLoad is never called on the main Window Controller.

我实际上发现最好不要对任何窗口使用主故事板。原因之一是因为使用 Storyboards(至少现在),当应用程序启动时无法拦截初始 segue,并且 windowWillLoad 永远不会在主窗口控制器上调用。

Instead, create separate storyboards for the Application and/or Document windows, and use an AppDelegate class to instantiate them. More information and a working example in this thread.

相反,为应用程序和/或文档窗口创建单独的故事板,并使用 AppDelegate 类来实例化它们。此线程中的更多信息和工作示例