How to use NSToolBar in Xcode 6 and Storyboard?

后端 未结 6 2065
予麋鹿
予麋鹿 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条回答
  •  青春惊慌失措
    2020-12-05 06:17

    Here is a general solution for the outlets and actions. it allows you to preform all the the same functions as an iboutlet would for a tool bar item and also allows you to set the button to a function instead of creating an ibaction. hope it helps :P

    override func viewDidLayout() {
    var x = self.view.window?.toolbar?.items[1].label
    println(x)
    if(self.view.window?.toolbar?.items[0].label! != "Check")
    {
        toobarediting()
    }
    println("didlay")
    }
    
    func toobarediting() {
    self.view.window?.toolbar?.insertItemWithItemIdentifier("Check", atIndex: 0)
    }
    
    func toolbarcheck(functiontoset: Selector) {
    var y = self.view.window?.toolbar?.items[0] as NSToolbarItem
    y.action = functiontoset
    if(functiontoset != nil)
    {
        y.enabled = true
    }
    }
    

    Here is a link to my question attempting to get a cleaner answer http://www.stackoverflow.com/questions/27371439/use-nstoolbar-outlet-xcode-6-and-storyboard/27374449 but it looks like from the answers i have gotten so far this is the best option.

提交回复
热议问题