swift - Multiple buttons for one action without IB -


in view controller, have 10 buttons. each button has tag , buttons call same action (separate switch (sender.tag), case 0 -> case 9 differentiate button selected). made ib, connected buttons (@iboutlet) same @ibaction , good. want programmatically, without ib.

so removed @iboutlet's , @ibaction create new buttons (let mybutton1 = uibutton()) , new action (func newaction(sender: uibutton)). tried addtarget: same selector new buttons, app crashes.

anyone has idea fix please ?

this should work:

func newaction(sender: uibutton) {     ... } ... mybutton1.addtarget(self, action: "newaction:", forcontrolevents: .touchupinside) mybutton2.addtarget(self, action: "newaction:", forcontrolevents: .touchupinside) mybutton3.addtarget(self, action: "newaction:", forcontrolevents: .touchupinside) 

Comments

Popular posts from this blog

swift - Button on Table View Cell connected to local function -

dns - Dokku server hosts two sites with TLD's, both domains are landing on only one app -

c# - ajax - How to receive data both html and json from server? -