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

c# - Binding a comma separated list to a List<int> in asp.net web api -

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

Delphi 7 and decode UTF-8 base64 -