3

This works...

  1. Create a new project using storyboards and swift.

  2. Using IB add new menu "Thing" with one item "foo" to the main application menu bar.

  3. Add the following to the AppDelegate....

    @IBAction func appfoo(sender: AnyObject) {
        println("yay appfoo!")
    }
    
  4. In IB drag from the menu item "foo" to the "First Responder" and select "appfoo"

  5. Run app, select menu item "foo" and "yay appfoo" gets printed out.


This doesnt...

  1. Create a new project using storyboards and swift.

  2. Using IB add new menu "Thing" with one item "foo" to the main application menu bar.

  3. Add the following to the NSViewController....

    @IBAction func appfoo(sender: AnyObject) {
        println("yay viewfoo!")
    }
    
  4. In IB drag from the menu item "foo" to the "First Responder" and select "viewfoo"

  5. Run app, select menu item "foo" and "yay viewfoo" does not get printed out.


Which from what I can tell from reading around means that my NSViewController is not in the responder chain. How do I add it? Or is there something else I should do?

pkamb
  • 33,281
  • 23
  • 160
  • 191
SaltyFleg
  • 31
  • 2
  • I've deleted answer. It's wrong. All you need is in http://stackoverflow.com/questions/20061052/how-to-add-nsviewcontroller-to-a-responder-chain?rq=1 – Warren Burton Jun 08 '15 at 11:29
  • Hmmm which answer worked for you? The accepted answer there links to a tutorial which suggests adding an IBOutlet for the NSViewController to a subclassed NSView, I just tried that and IB wont let me hook it up (remember I'm using storyboards and swift). The second answer there suggests you dont have to do that and can just add code to your awakeFromNib in the NSViewController. Which I did and which also didnt work. – SaltyFleg Jun 09 '15 at 02:23
  • As of Yosemite the View Controller is in the responder chain and your second method works. See https://developer.apple.com/videos/play/wwdc2014/212/ at 20:35 mark. – wcochran Mar 29 '17 at 17:38

0 Answers0