I have a tableView with cells. Each cell has an imageView. When I click on the imageView, I want to execute a function with parameters that I pass in. The only way that I know how to work with clicking on imageViews is something like this:
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(printNumber))
cell.imageView.addGestureRecognizer(gestureRecognizer)
@objc func printNumber(){
print("4")
}
Now, imagine this exact same thing, but I want to pass the number to print into the function I've seen a million different posts about how you can't pass parameters into selectors, so I'm not sure what to do in this case.
I want to do something like this (I know you can't do this)
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(printNumber(num: 4))
cell.imageView.addGestureRecognizer(gestureRecognizer)
@objc func printNumber(String: num){
print(num)
}
I need to do this because every button will have a different output when pressed, depending on some other variables in the cell.