0

I am trying to display a new image based on a user tapping the image view. I have added a UITapGestureRecognizer on top of the UIImageView which has been defined a "displayPhoto" and connected it as an outlet to the view controller.

@IBOutlet weak var displayPhoto: UIImageView! @IBAction func changeImage(_ sender: UITapGestureRecognizer) { displayPhoto.image = UIImage(named: "myimage") } 

The sent action is listed as follows:

sent actions

When I run the app and click on the image, nothing happens. I've even tried to make the first line of the IBAction function a fatal error but nothing happens. What am I missing?

Thanks in advance for any help.

The full view and connection

Tap Gesture Recognizer Window

7
  • The UIImageView already has "User Interaction Enabled" checked Commented Apr 23, 2020 at 22:13
  • Also done. If I hover on the filled circle next to the outlet definition, it highlights the tap gesture recogniser on the scene dock Commented Apr 23, 2020 at 22:16
  • When I hover over the sent action, it highlights the whole view controller. I have just named it view for the sake of the example.. Commented Apr 23, 2020 at 22:19
  • Have changed the view to be "New item" and pasted a photo showing the reference outlet Commented Apr 23, 2020 at 22:27
  • Added photo of window connections and sent actions Commented Apr 23, 2020 at 22:31

1 Answer 1

0

Firstly you try; clean your project

command+option+shift+K

The first case cannot be empty

You should add a picture.

 override func viewDidLoad() { super.viewDidLoad() displayPhoto.image = UIImage(named: "firsCase") } 
Sign up to request clarification or add additional context in comments.

3 Comments

The UIImageView has a default display photo
It is created as nil you created. You have to set the default picture under it. Please You try
The attributes inspector has an image selected for this

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.