Answer the question
In order to leave comments, you need to log in
How to pass an ImageView to a function argument?
everything is transferred by tap cell.addGestureRecognizer(tap)
, but if I want to transfer exactly ImageView, then it does not assign anything.
What could be the issue?
Tried to bind tag = indexPath.row
He didn't want to pass it either.
@objc func imageTapped(sender: UITapGestureRecognizer) {
if sender.state == .ended {
print("UIImageView tapped")
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// dequeueReusableCell - подгружает из очереди переиспользуемую ячейку
guard let cell = tableView.dequeueReusableCell(
withIdentifier: NewsTableViewCell.identifier,
for: indexPath
) as? NewsTableViewCell else {
fatalError()
}
cell.configure(with: viewModels[indexPath.row])
///
let tap = UITapGestureRecognizer(target: self, action: #selector(self.imageTapped))
cell.imageView?.isUserInteractionEnabled = true
cell.imageView?.addGestureRecognizer(tap)
///
return cell
}
Answer the question
In order to leave comments, you need to log in
Look - the standard cell already has an embedded imageview. But, I suspect you put yours in. And this means that you are assigning a standard imageview to the tapgestura, and not your own.
Make another method, ala cell.configure, only configureImageGesture, where you pass the gestura. And inside the method, already assign the gestura to your imageview.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question