On Sep 2, 2015, at 4:19 PM, Alex Hall <[email protected]> wrote:
> Regarding connection to First Responder, I think I'm still missing a step. I
> have a menu item I want to connect to First Responder so that, as I
> understand it, I can then make an outlet and action for that item in my view
> controller (stop me if I'm wrong there).
You won't be able to have an outlet of the view controller connect to the menu
item. Connecting the menu item's action to First Responder doesn't change
that. It just allows the menu item to invoke the action on the view controller
through the indirect mechanism of the first responder and the responder chain
originating there. (But only if the view controller is in that responder chain
due to its view or a subview having focus.)
> Here's what I did:
>
> * select the menu item in the storyboard's outline table
> * go to the Connections Inspector and find the "Sent Actions"
> * There's a button in there that VO identifies as "connection action, AX
> button". I locked the mouse down on that.
> * I went back to my outline, located First Responder in my application scene,
> put VO on the unlabeled button on to its right, and released the mouse. A
> connection appeared in the Connections Inspector for First Responder, so that
> seems to have worked.
> * Note: a new window appeared, with a massive list of actions, from
> "superscript" to "cut" to "spellcheck", and tons more. VO read a few
> unlabeled buttons in here, but mostly it just found objects that were
> "unknown". Enter did nothing, so I eventually had to press escape. I still
> don't know what that window was for or if I was supposed to do something with
> it.
Connecting the menu item's action actually needs to set two pieces. First is
the target. You've successfully chosen the First Responder placeholder. (As
previously discussed, this actually results in the menu item having nil for its
target which is what you want.) The second piece is which action method it
should invoke. That second window is a menu to allow you to select the action
method. First Responder lists all known action methods of all known responder
classes because any responder could be in the responder chain. That's why the
list is so long. The menu supports type-to-select, although it doesn't quite
work like I'm used to.
If you didn't successfully select something from that menu, then either the
action connection wasn't made or it was made to some arbitrary action method.
> * If I'm following yesterday's discussion, I should now be able to make an
> IBOutlet in my view controller for the menu item, since said menu item is now
> hooked to First Responder.
Nope.
> When I did, it refused to connect.
Right.
> * In case I misunderstood, and I have to keep the outlet in AppDelegate but
> can put just the action anywhere, I connected the menu item to an outlet in
> AppDelegate and then tried dragging from the "new action AX button" in the
> menu item's Connections Inspector to my IBAction method, in the view
> controller. Unfortunately, the mouse simply refused to route to the button I
> needed to drag, yet it routed to any other connection button I tried.
First, do you actually need an outlet to the menu item? What do you plan to do
with that? It's not required to get the menu item working. It might be useful
if you wanted to do run-time manipulation of the menu item, but there are also
other (likely better) ways of doing that, like menu validation. That would
keep the manipulation inside the class that implements the action method.
If you really do need an outlet, it has to be from the app delegate. It sounds
like you were able to make that connection. Connecting the menu item's action
is unrelated. You described earlier doing that successfully, too, although
there's some doubt about whether you were able to select the correct action
method.
Something to consider if Xcode's interface is just not accessible enough (after
filing a bug!) would be to connect an outlet from the app delegate and then
have the app delegate set the item's target and action in code, such as in the
-applicationDidFinishLaunching: method. The code would reference the menu item
via the outlet. So, it would be something like:
self.myMenuItem.target = nil;
self.myMenuItem.action = @selector(myActionMethod:);
Regards,
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com
This email sent to [email protected]