Setting targets and actions in Xcode

Discussion in 'iOS Programming' started by Aarend, Mar 1, 2014.

  1. Aarend macrumors newbie

    Mar 1, 2014
    Hi, i'm using Xcode version 5.0.2. To set a target from a button i have to Control-drag this button from the canvas to File's Owner. File's Owner will then highlight. For no reason this doesn't work and i can't find a way to make this happen, what am i doing wrong? :(
  2. xStep macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    First, in you source file, usually the .h file, you need a line like the following. This is from MyClassViewController.h file.

    - (IBAction) tapTheButton: (id) sender;
    The attached image displays that the File's Owner needs to be of the class your dealing with. Look to the right.

    Attached Files:

  3. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia
    It only works if you already have IBActions declared in your header file.

    The better thing to do is to open an assistant editor to the view controller's header file, and control-drag from the button into the header. You will be presented with a popover that lets you create an outlet or an action. It defaults to creating an outlet. You have to switch the popup to action, set it to make the sender's type UIButton instead of id, and name the action. When you do this, it does 3 things in one:

    1. It creates the IBAction method definition in the header.
    2. It creates an empty IBAction in the .m file
    3. It connects an IBAction link to the action method in the interface file.

Share This Page