如何在 Xcode 6 和 Storyboard 中使用 NSToolBar? [英] How to use NSToolBar in Xcode 6 and Storyboard?

查看:24
本文介绍了如何在 Xcode 6 和 Storyboard 中使用 NSToolBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在 Xcode 6 中使用 Swift 和 Storyboard 的 Cocoa 应用程序进行构建,但是我如何在那里使用 NSToolbar ?

I've been trying to build on a Cocoa app that uses Swift and Storyboard in Xcode 6, but how can I use NSToolbar there?

在 Xcode 5 和 xib 中,您可以将对象库中的 NSToolbar 添加到任何 .xib 文件中,然后单击添加的工具栏将其展开并将连接从那里的任何项目拖放到AppDelegate.h 文件.通过这种方式,您可以创建 IBActionIBOutlet 连接.我确认如果您在 Xcode 6 中使用 Swift 和非故事板也可以做到这一点.但是,在 Xcode 6 和 Storyboard 环境中似乎并非如此.

In Xcode 5 and xib, you can add NSToolbar from within Object Library to any .xib files and then click on the added toolbar to expand it and drag and drop a connection from any items there to a AppDelegate.h file. In this way you can create a IBAction or IBOutlet connection. I confirmed that this can also be done if you use Swift and non-storyboard in Xcode 6. However, it looks like this is not the case in Xcode 6 and Storyboard environment.

我首先在 Xcode 6 中创建了一个使用 Storyboard 的项目,但随后我无法将对象库中的 NSToolbar 添加到 Storyboard 中的视图控制器.所以我将它添加到 Storyboard 中的 Window Controller 的 Window 对象中.但是,通过这种方式,我无法从展开的工具栏中的任何项目创建这些连接到 AppDelegate.swiftViewController.swift.

I first created a project that uses Storyboard in Xcode 6, but then, I wasn't able to add a NSToolbar from within Object Library to a View Controller in Storyboard. So I added it to Window Controller's Window object in Storyboard. However, in this way I cannot create those connections from any items in the expanded toolbar to either AppDelegate.swift or ViewController.swift.

所以我的问题是:

  • 创建一个使用 NSToolbar 的故事板应用是否可行?
  • 如果可行,将NSToolbar 添加到Window Controller 是否是在Storyboard 中使用NSToolBar 的正确方法?
  • 最后,如何在那里创建 @IBOutlet@IBAction 连接?
  • Is it feasible to create a storyboard app that uses NSToolbar?
  • If it is feasible, is the addition of NSToolbar to the Window Controller the proper way to use NSToolBar in Storyboard?
  • Finally, how can I create @IBOutlet and @IBAction connections there?

我发现@GeorgeVillasboas 接受的答案仅适用于 @IBAction.我仍在寻找如何创建 @IBOutlet 连接...

I found that the accepted answer by @GeorgeVillasboas only works for @IBAction. I am still looking for how to create an @IBOutlet connection...

推荐答案

我遇到了同样的问题.该解决方案适用于 Objective-C 和 Swift 项目.

I had this very same problem. The solution works for both Objective-C and Swift projects.

在 OSX 上使用 Storyboards,它创建了一个 NSWindow 实例,并按照您的描述将另一个 NSViewController 作为其 Window Content Segue.

Working with Storyboards on OSX, it creates an instance of NSWindow and segues to another NSViewController as its Window Content Segue, as you described.

在您的 ViewController 上,创建一个标准的 IBAction 以在单击工具栏时接收操作.要将它与 NSToolbar 连接起来,只需从 NSToolbarItem 控制拖动(或左键拖动)到 FirstResponder 对象,如下图所示.

On your ViewController, create a standard IBAction to receive the action when the toolbar is clicked. To wire it up with the NSToolbar, just control-drag (or leftClick-drag) from your NSToolbarItem to the FirstResponder object, as shown on the picture below.

这将打开一个巨大可用连接列表.您的 IBAction 将在该列表中.刚刚选择它,你很高兴.

This will open a HUGE list of available connections. Your IBAction will be on that list. Just selected it and you're good to go.

希望这有帮助!

这篇关于如何在 Xcode 6 和 Storyboard 中使用 NSToolBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆