Know which button invoked the action

Asked

Viewed 48 times

1

I have the following problem, I have a pickView that will be equal for two actions, however these actions have to perform parameter passage , or need to know which button invoked the action. Would anyone know how to solve this problem ? Ah I have two buttons that I invoked. Thank you

1 answer

3


Once you set the two buttons:

@IBOutlet weak var btnPrimeiro: UIButton!
@IBOutlet weak var btnSegundo: UIButton!

Your action in fact may be only one for N buttons. This action takes the button itself as parameter, so you can check which of the buttons was pressed:

@IBAction func acaoBotao(sender: UIButton) {
    if sender == btnPrimeiro {
        // Primeiro botão pressionado
    } else {
        // Segundo botão pressionado
    }
}

Of course, this for both the buttons and the action connected by Builder interface.

  • Friend understood , but this btnFirst what would be ? Algim id ? Or the outlet ? Thank you

  • Is the outlet of each button on Builder interface. You make the connection both of IBOutlet how much of IBAction. Of outlets for each button and the action to the buttons.

  • OK I will test ... Thank you

  • It worked buddy, thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.