I write with Swift 4 and try to write a function that send categoryId as action but I couldn't write .I think my syntax is wrong.If I write function without parameters its not a problem but I get error with parameters functions. Could you say me how to use selector?
@objc func sendCategoryIdToPackageSelectionVC(categoryId : Int){
MarketVC.categoryId = categoryId
self.performSegue(withIdentifier: "sequeGoToPackageSelection", sender: nil)
}
func addTapFeatures(){
taplabel1 = UITapGestureRecognizer(target: self, action: #selector(self.sendCategoryIdToPackageSelectionVC(categoryId:2)))
taplabel1?.cancelsTouchesInView = false
self.labelFirst.addGestureRecognizer(taplabel1!)
}
I get an error saying that the action selector doesn't refer to any objc method.
i think, you can't directly use selector to pass parameter. try some thing like this you should create an @objc method that calls handleTap(modelObj:myModelObj).
@objc func someMethod() { // name this properly!
handleTap(modelObj: myModelObj)
}
Then you can pass this as a selector:
#selector(someMethod)
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