Swift - determine which button was pressed with switch

前端 未结 5 633
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 01:04

I have 4 buttons that call one function. Depending on which button was pressed i need to hide button inside of function that called after pressing.I dont know which button w

5条回答
  •  醉酒成梦
    2020-12-17 01:31

    Rather then using a switch statement you can just use the sender directly.

    Note that you need to specify that the sender is a UIButton (therefore this will only work if the function is only called from a button).

    @IBAction func submitButton(sender: UIButton) {
    
        /* extra code here */
    
        sender.enabled = false
    
    }
    

    This reduces the code and also allows you to add extra buttons without code changes.

提交回复
热议问题