Know which button invoked the action

1

I have the following problem, I have a pickView that will be the same for two actions, but these actions have to perform parameter passing, ie I need to know which button invoked the action. Would anyone know how to solve this problem? Oh, I have two buttons that I invoked. Thanks

    
asked by anonymous 05.10.2015 / 02:12

1 answer

3

Once you have defined the two buttons:

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

Your action may actually be only one for N buttons. This action gets the button itself as a parameter, so you can check which button was pressed:

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

Of course, this is for both the buttons and the action bound by the interface builder .

    
05.10.2015 / 13:50