please anyone tell me, How to send additional parameter in addtarget function in swift 2.2? Example:
button.addTarget(self, action: #selector(classname.myFunc(_:)), forControlEvents: UIControlEvents.TouchUpInside))
func myFunc(sender:UIButton){
print(“i am here“)
}
to
func myFunc(sender:UIButton,parameter:String){
print(“i am here“)
}
You can create a subclass of UIButton, add one property named parameter which you want to pass as an extra parameter.
In addTarget(), you can only choose passing the caller or not. In this case, the caller is a UIButton.
So use the subclass and call addTarget(), then you can get the string which you want send:
func myFunc(sender: customUIButton) {
// do something with sender.parameter
}
Hope it can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With