Frankie
Frankie

Reputation: 185

One button for several actions

I am having trouble configuring a button that:

...and so on

Is there any way to configure that button?

Thanks

Upvotes: 2

Views: 123

Answers (2)

redribben
redribben

Reputation: 186

If you were interested in keeping track of the number of clicks while also doing the job of the 3 alternating tasks:

var counter : Int = 0

@IBAction func buttonClicked(_ sender: Any) {
    counter+=1
    //print(counter)
    switch counter % 3 {
    case 1:
        // First Action
    case 2:
        // Second Action
    default:
        // Third Action
    }
}

Upvotes: 2

Maryam Fekri
Maryam Fekri

Reputation: 625

Do as below in your button action:

var counter = 0

@IBAction func buttonTapped(_ sender: Any) {
    counter += 1
    switch counter {
    case 1:
        // do your action
    case 2:
        // do your action
    case 3:
       // do your action 
       counter = 0
    default:
        break
    }
}

Upvotes: 1

Related Questions