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

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

问题描述

我一直在试图在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 文件。这样,您可以创建 IBAction IBOutlet 连接。我确认这也可以做,如果你在Xcode 6中使用Swift和非故事板。但是,它看起来像在Xcode 6和故事板环境中不是这样。

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中的View Controller。所以我把它添加到窗口控制器的窗口对象在故事板。但是,这样我不能从扩展工具栏中的任何项目创建这些连接到 AppDelegate.swift ViewController.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 到窗口控制器在故事板中使用 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窗口内容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.

希望这有助于!

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

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