Swift - determine which button was pressed with switch

前端 未结 5 629
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  Happy的楠姐
    2020-12-17 01:36

    Why you always want to use tags to determine the UIButton ? If the called function has a sender parameter then you know the UIButton which called the function through this parameter.

    func buttonClicked(sender: UIButton)
    {
       switch sender {
       case button1: // Do something
       case button2: // Do some other stuff
       ...
       default: ()
       }
    
    }
    

提交回复
热议问题