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 -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -