How to use NSToolBar in Xcode 6 and Storyboard?

后端 未结 6 2068
予麋鹿
予麋鹿 2020-12-05 06:05

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?

In Xcode 5 and xib, you can add

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 06:30

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

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

    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.

    Wiring up a NSToolbar on XCode 6

    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.

    Hope this helps!

提交回复
热议问题