0

Hi so I'm looking to fill my UIImageView with an image that I have in my files, and I don't want a specific one all the time, but a different one every other time.

That is why I created an array with the names of all the images that I would like to use.

The only problem is there is always this error, exc_bad_instruction (code=exc_i386_invop subcode=0x0) , that constantly comes up everytime I try to run the code. Here is my code,

please help: enter image description here Also I am running xcode version 7 if that makes any difference.

Aseem Rai
  • 21
  • 1
  • 3
    image1 is nil and you are trying to reference it. Are you calling it before viewDidLoad and all the UI elements are initialized? I give you credit for the basketball names though. – JRD Oct 26 '15 at 06:28
  • Your `UIImageView` image1 is nil. Can you post code where you are creating this view ? If its in storyboard then you need to call this method `createSet1()` after `viewDidLoad()` – GoodSp33d Oct 26 '15 at 06:38
  • this link might be helpful http://stackoverflow.com/a/24372873/5362916 – Uma Madhavi Oct 26 '15 at 10:09

2 Answers2

0

Your UIImageView is nil and it can't be if you are creating it. You have to set the image BEFORE you create the view. The image should already be ready and waiting when the view is created.

Machavity
  • 30,841
  • 27
  • 92
  • 100
mccoyLBI
  • 171
  • 14
0

The image (image1) view you are trying to set image is nil. You have to first create the image view, and then assign image.

Try this code:

image1 = UIImageView()
//Set up frame, size, etc
image1.image = UIImage(named: imageName)