How to make an automatic call to the @IBAction function

Hi, I'm not sure how to make the click function for @IBAction automatically call in Swift.

Let's say I have a timer function, when the countdown is over, I need to call the @IBAction Click function, as shown below, instead of asking the user to press the button

How to do it fast?

 @IBAction func DoSomeTask (sender: UIButton) {

 - code--

 }
+8
ios swift
source share
1 answer

You can either change the IBAction signature by specifying its parameter. Optional, like this:

@IBAction func doSomeTask(sender: UIButton?) { // code } 

and then call it with nil as an argument:

 doSomeTask(nil) 

Or you can use IBAction as a wrapper for a real function:

 func doSomeTaskForButton() { // ... } @IBAction func doSomeTask(sender: UIButton) { doSomeTaskForButton() } 

means you can call doSomeTaskForButton() from anywhere.

+26
source share

All Articles