Uibutton extends Uicontrol, which uses the concept of target/action for the treatment of events. Action is basically a method that will be triggered when the event occurs. Target is the object that receives the message, that is, that must implement the action.
In the example below I added a button in the storyboard and connected to the outlet. So in the method viewDidLoad
defined the method to be called (buttonClicked - action), in the view controller instance (self - target). The last parameter is the type of event to be detected. In this case I used Touchupinside, which is the regular click.
class ViewController: UIViewController {
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
}
func buttonClicked(sender:UIButton) {
println("Botão pressionado")
}
}
Thank you very much @Rafaelleao, that’s what I was looking for.
– Filipe Amaral Neis