ios - Is it possible to override action method for UIButton in Swift? -


i have 1 uibutton. want use same uibutton execute multiple actions. first i'm setting action button programmatically.

button1.addtarget(self, action: #selector(viewcontroller.function1), forcontrolevents: .touchupinside) 

next, want discard funtion , want add other action.

button1.addtarget(self, action: #selector(viewcontroller.function2), forcontrolevents: .touchupinside) 

is possible override existing target button?

the case suggested wont override previous action add second action button resulting in viewcontroller.function1 , viewcontroller.function2 being called.

you need remove previous action target before adding new 1 using

button1.removetarget(self, action: #selector(viewcontroller.function1), forcontrolevents: .allevents)

or remove previous actions before adding new one

button1.removetarget(nil, action: nil, forcontrolevents: .allevents)


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -