Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call a button function when the button is not being pressed

I have an IBAction connected to a button, and I wanted to know if there is any way to run that function even if the button is not being pressed. This is what I tried...

Note: I am using swift for this project.

//I get an error when I type this code?
self.buttonPressed()

@IBAction func buttonPressed(sender: AnyObject) {

    print("Called Action")

}
like image 862
nachshon fertel Avatar asked May 01 '15 12:05

nachshon fertel


1 Answers

Make your sender argument optional and pass nil to ButtonPressed.

self.ButtonPressed( nil )


@IBAction func ButtonPressed( sender: AnyObject? ) {
    println("Called Action")
}
like image 65
Satachito Avatar answered Sep 21 '22 06:09

Satachito