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

renaming files in a directory using python or R -

html - outline-style different in chrome compared to firefox and internet explorer -

ruby on rails - Carrierwave Timeout -