Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting actions to buttons in Xcode

How do I connect a button added in Interface Builder to an action? This is what my instructions for adding a forum component in to my app. It says "Connect the action of that button to your "launchSatisfactionRemoteComponent:" method in IB." This would need to happen in my "Support.xib" window. Where is the code where you connect the action to that?

like image 569
Amar H-V Avatar asked Jul 05 '11 03:07

Amar H-V


People also ask

How do I link a button in Xcode?

Xcode connects your storyboard to Swift code by using a combination of the Identity Inspector, IBOutlets and IBActions. On the right side of your addressbar, there is a button you can click to activate the Assistant Editor. The first thing you might notice, is the lack of screen space for each open file.

How do I assign an action button in Xcode?

You need to first select your button, then hold the control ⌃ button on your keyboard and then drag that across to your view controller. That will then give you the option of what to name your method etc.

How do I connect actions in Xcode?

Simply control-click on the object in storyboard, and drag the cursor into the implementation file. The least common way of making a connection is to programmatically type the outlet or action in the implementation file using the keyword, IBOutlet or IBAction.


1 Answers

In your code, add the method to handle that action. For instance,

.h file

- (IBAction)buttonTapped:(UIButton *)sender;

.m file

- (IBAction)buttonTapped:(UIButton *)sender
{
  NSLog(@"Button Tapped!");
}

Now, open you xib file, right click to File's Owner, there you should see your method, drag the plus circle onto your button. You should see a bunch of different actions, most of the time touchUpInside is what you are looking for.

like image 113
Robert Childan Avatar answered Sep 18 '22 21:09

Robert Childan