Uiimage change problem

Creating a magic 8 ball app and the array is set to the images I want but when I set the UIImage name for the IBoutlet xcode wont recognize it. So the IBaction button can be pressed but no image change. I understand basic dot notation if ur wondering. Please help

Hi David,
Can you provide a screen capture of your storyboard and your viewController file while in Assistant Editor mode showing the IBOutlet connections.

Hi David,

Pop your imageView line of code between the {} curly brackets of your AskButton IBAction. That will call the imageView line.



It looks like you have tried to link the array you have defined on line 21 to something in storyboard. That won’t work.

I assume that this is what you want to do:

  • Each time you click on the Ask button, change the image that is displayed on the screen.

If that is the case and you want to select an image at random from ballArray then move the line where you define the array of images (Line 21) up tp the top of your ViewController code where properties are normally defined. ie, just inside the class definition at line 11.

In your askButtonTapped() function you could do this:

imageView.image = ballArray.randomElement()
1 Like

![Screen Shot 2020-04-25 at 5.34.26 PM|690x431](upload://fF

6QY1S00UVgoz81eSYKOja0ezb.png) This is a bootcamp I’m taking but her code runs but mine doesn’t, it keeps telling me the IBaction outlet key isn’t code compliant. I understand what it means I’m just stumped why it rejects me.

And yes I did move the ball array to the UIImage class first and got the same issue

Thank you so much for ur support. I fixed the problem tho thanks to becodable.com. VERY MUCH APPRECIATE IT