user3992901
user3992901

Reputation:

How to fix 'imageNamed:' error

I am trying to create a program that will randomly generate a photo. I am using this code to do so:

    int imageSwitch = rand() % 2;

switch (imageSwitch) {
    case 0:
        Picture.image = [UIImageView imageNamed:@"8292.jpg"];
        break;

    case 1:
        Picture.image = [UIImageView imageNamed:@"apple sauce.jpg"];

    default:
        break;

However, I always get the same error about imageNamed:, which is "No known class method for selector 'imageNamed:'" Does anyone know how to fix this error?

Upvotes: 0

Views: 381

Answers (2)

l0gg3r
l0gg3r

Reputation: 8954

imageNamed: is an class method of UIImage, so you need to do

int imageSwitch = rand() % 2;

switch (imageSwitch) {
   case 0:
      Picture.image = [UIImage imageNamed:@"8292.jpg"];
      break;

   case 1:
      Picture.image = [UIImage imageNamed:@"apple sauce.jpg"];
      break;
default:
    break;

Upvotes: 1

Bo A
Bo A

Reputation: 3154

imageNamed: is a class method of UIImage, not UIImageView.

Upvotes: 1

Related Questions