Ryan
Ryan

Reputation: 1

Image won't appear in Xcode

I'm a first time programmer and i'm trying to make a soundboard app. Its not finished yet and it is pretty basic. I have a main menu with one button. When this button is pressed, a different background image should appear along with a back button. The image does not change. here is the code:

-(IBAction)redgradient {

    UIImage *img = [UIImage imageNamed:@"redgradient.jpg"];
    [imageView setImage:img];

}

-(IBAction)redgradient2 {

    UIImage *img = [UIImage imageNamed:@"redgradient2.png"];
    [imageView setImage:img];

}

I have mentioned the IBActions in the H file and used an IBOutlet of ImageView. Help is appreciated.

Upvotes: 0

Views: 1229

Answers (2)

Lukas Wiklund
Lukas Wiklund

Reputation: 826

Here's a more simple way to do that, test if this works better:

-(IBAction)redgradient {

    imageView.image = [UIImage imageNamed:@"redgradient.jpg"];

}

-(IBAction)redgradient2 {

    imageView.image = [UIImage imageNamed:@"redgradient2.png"];

}

Check if the images ends on .jpg or .png if that is the problem.

Upvotes: 2

PengOne
PengOne

Reputation: 48398

Here are a few things to check:

  1. The image files have been added to the project.
  2. The image names are exactly as they appear in the project (case sensitive and correct format).
  3. The connections are properly established in the IB.

Upvotes: 0

Related Questions