Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IBOutlet and IBAction in Swift

Tags:

swift

iboutlet

I connected a IBOutlet and IBAction to my button variable from Interface Builder to my View Controller. How do I add an action method to the button in Swift? This code doesn't seem to work.

@IBOutlet var OK: UIButton!
@IBAction func OK(sender: UIButton){}

The Objective-C equivalent I found is:

@interface Controller
{
    IBOutlet id textField; // links to TextField UI object
}

- (IBAction)doAction:(id)sender; // e.g. called when button pushed
like image 655
linux-user Avatar asked Sep 14 '15 19:09

linux-user


1 Answers

One way to do it, is control-drag from your button to your viewcontroller and choose action: enter image description here

If you have connected your button's action, your code should work just fine.

like image 106
Prontto Avatar answered Nov 05 '22 08:11

Prontto