Get button pressed id on Swift via sender

后端 未结 15 1131
广开言路
广开言路 2020-12-01 04:21

So I have a storyboard with 3 buttons I want to just create 1 action for all those 3 buttons and decide what to do based on their label/id...

Is there a way to get s

15条回答
  •  盖世英雄少女心
    2020-12-01 05:12

    I'm not a fan of any of the above:

    switch sender as! NSObject {
    case self.buttoneOne:
        println("do something when first button is tapped")
    case self.buttoneTwo:
        println("do something when second button is tapped")
    default:
        println("default")
    

    }

提交回复
热议问题