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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With