Re: Unable to create outlets/connections for NSMenuItems, but other controls work
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: Alex Hall <email@hidden>
- Date: Tue, 01 Sep 2015 23:51:12 -0400
> On Sep 1, 2015, at 11:15 PM, Quincey Morris <email@hidden> wrote:
>
> On Sep 1, 2015, at 18:12 , Alex Hall <email@hidden> wrote:
>>
>> I'm not clear on the second option--the First Responder?
>
> It’s a pretense, sort of, but it’s very simple when you know what’s really going on.
>
> When you connect a UI element to an action in a controller, the NIB element has an action selector (the name of the method to call) and a target link which points to the controller. To perform the action, the UI element performs that selector on that controller object. There may be some validation involved, but the responder chain is not used — the target is known in advance.
>
> When you connect a UI element to “First Responder” in IB, you are really leaving the target link nil, although the selector is still specified (which is how it’s different from not connected at all). To perform the action, the UI element asks the frameworks to look up the responder chain, starting from the current first responder, to see if there is an object that responds to the selector and is prepared to accept the action. If so, that object performs the action. (Look at the NSApplication method ‘sendAction:to:from:’ if you want to understand how this is implemented. The magic is hiding right there out in the open.)
>
> So, “First Responder” in IB is a placeholder element that represents whatever object will accept the action at runtime (in the context current at the time). IB aggregates all action methods it knows about — from everywhere in your app and in the frameworks classes — and pretends that the “First Responder” placeholder responds to them all, which is what allows you to connect any action to First Responder anywhere in your storyboard.
>
> Note also that there’s a “First Responder” in every scene in your storyboard. That effectively makes every action available from every UI element, across scene boundaries that actions cannot otherwise cross at design time, at the cost of deferring resolution to runtime, plus the conceptual cost of following what’s going on in IB.
I think I'm mostly following; thanks to you and Ken for your time. I'll be looking online to see if there are any tutorials on doing this, but as you have both indicated, storyboards on OS X are still new and haven't been explained overly much. The idea of First Responder makes a lot of sense, my block is when I try to think about how making a connection between my menu items and First Responder will then let me hook up an action method.
My problem now--and this also lets us get back to Xcode usage--is connecting these to the First Responder. I see my menu item and First Responder in the outline table, but I can't get them to connect. You saw what VoiceOver requires me to do to make connections to view controllers; control-dragging is simply not an option unless and until Apple addresses that problem.
I've tried dragging the unlabeled button next to the menu item to First Responder, but that just moved my menu item. I've tried going the other way, but First Responder didn't move and I see no connections in the inspector. I tried dragging a new referencing outlet for the menu item from the Connections Inspector to the menu item's unlabeled button, but no dice. I realize none of you are VO users, but can you think of any alternative methods I might try?
>
>> Using appDelegate works, as I said, but it feels weird to split my UI code between that file and my view controller. I get why I have to, and I know that on OS X, it's more acceptable to put UI code in that file instead of a dedicated view controller, but the setup seems awkward.
>
> Indeed, it still preferable to avoid splitting the code, but with storyboards you need to hook the action up via First Responder to achieve that. Then there’s no difficulty with having the outlets in the view controller itself.
>
> The reason this is messier on OS X is that in iOS you don’t really deal with global UI elements like menu items or windows. Nor do you typically have multiple top-level view controllers presented simultaneously — you generally segue between individual controllers instead. Unfortunately, when Apple brought storyboards to OS X, they didn’t provide any additional conceptual documentation (AFAIK) that explained how storyboards dealt with OS X’s extra complexity.
>
--
Have a great day,
Alex Hall
email@hidden
_______________________________________________
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