Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode quickly jump to Action associated with a Control

Is there a quick way to jump to an action associated with a control.

Say there is a button on a XIB file that has an associated action. The way to find the code associated with this is rather tedious. Is there a short cut that can quickly jump to the code.

I am spoiled by Visual Studio - double click on a button and it takes you to it's handler

like image 546
OneGuyInDc Avatar asked Apr 25 '13 11:04

OneGuyInDc


People also ask

How to jump to a Line in Xcode?

Jump to Line ( ⌘ + L )

How to search method in Xcode?

Searching for text in Xcode is quite easy. Type Command-Shift-F and off you go.

How do I navigate back in Xcode?

In Xcode 4 preferences, it's configured to be ^ + ⌘ + ← (control-command-left arrow) to navigate back and ^ + ⌘ + → (control-command-right arrow) to navigate forwards.

How do I create an action in Xcode?

Hold down the Control key and drag (or right-click-and-drag) from the control in question over into your class @interface . Let the mouse button go when Xcode indicates a successful drag with a horizontal line. In the window that pops up, choose whether you want to create an outlet or an action.


2 Answers

The fastest way I know to at least get quickly to the source file in which the action resides is the following:

  1. select the button in the UI editor
  2. hit ctrl+1 (this will open the “Related Files” drop down)
  3. navigate to the “Sent Actions” sub-menu, e.g. via s, enter
  4. select the relevant class (I think in this case there can only be one, so just hit enter again)

Once you are in the class, the action should be easy to find. If that's not the case, because your source file is so big, type ctrl+6 to open the “Document Items” drop down and start typing the name of the action. Once you see the action, select it via keyboard or mouse.

If you often don't know the name of the action, you will have to look it up before navigating to the class, e.g. by right clicking on the button.

like image 182
mistercake Avatar answered Oct 07 '22 07:10

mistercake


I would advise to use ^+++Enter to get to referenced code file. There you can search for @IBActions or @Outlets. If a UIButton has a segue attached, this method won't help to find it. To review a list of actions, segues and outlets you can select an object on the storyboard and press ++7 to open Connections Inspector on the right pane.

like image 1
Paul B Avatar answered Oct 07 '22 08:10

Paul B