• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Unable to create outlets/connections for NSMenuItems, but other controls work
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unable to create outlets/connections for NSMenuItems, but other controls work


  • Subject: Re: Unable to create outlets/connections for NSMenuItems, but other controls work
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 01 Sep 2015 23:12:18 +0000

On Sep 1, 2015, at 11:21 , Alex Hall <email@hidden> wrote:

The procedure for making connections to IBOutlets or IBActions seems to work perfectly when I use it to hook up NSButton, NSTextField, or NSTable controls. When I do the exact same thing for NSMenuItems, though, nothing happens.

As a matter of process, you’re not doing anything wrong, but I don’t believe what you’re trying to is possible. I admit to being a hazy on details here, because there’s a constantly shifting background of Xcode behavioral and UI changes, arising from the introductions of storyboards to the Mac UI paradigm.

In brief, you cannot make outlet or action links between scenes in a storyboard. This is likely a consequence of the fact that a storyboard is implemented as (among other things) a collection of nib files, and there isn’t any way of connecting between nib files, barring some special cases (e.g. via File’s Owner, and of course the First Responder fiction).

This makes sense, in a way, because a menu item is global, but a view controller (and hence any actions it defines) is in the active responder chain only sometimes — it’s not a globally valid destination.

For actions, I think you have two choices. One is to put the action method in the app delegate. Since this is part of the application scene, you can link a menu item to its actions, using the storyboard in IB. Or, link your menu item to First Responder within its own scene. (That is to say, leave it with a nil target.) That allows a run time determination to be made whether anything that responds to the action is in the responder chain at the time the menu item is used.

The same thing is true of the opposite direction. You can link outlets from (say) the app delegate to a menu item, because the app delegate is in the same storyboard scene as the menu item. If you really want an outlet from a view controller to a menu item, then you’ll have to add an outlet from the app delegate to the menu item, and make this a public property that the view controller can use. (It’s fairly rare to need to do this, though, since you can usually do whatever you want to the menu item at menu validation time, which is an override method in the view controller.)
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Unable to create outlets/connections for NSMenuItems, but other controls work
      • From: Alex Hall <email@hidden>
References: 
 >Unable to create outlets/connections for NSMenuItems, but other controls work (From: Alex Hall <email@hidden>)

  • Prev by Date: Unable to create outlets/connections for NSMenuItems, but other controls work
  • Next by Date: Re: Unable to create outlets/connections for NSMenuItems, but other controls work
  • Previous by thread: Unable to create outlets/connections for NSMenuItems, but other controls work
  • Next by thread: Re: Unable to create outlets/connections for NSMenuItems, but other controls work
  • Index(es):
    • Date
    • Thread