views:

61

answers:

1

Noob Alert,

I am trying to change an image in a UIImageView.

popCard is the IBOutlet pointed to the UIImageView - which is blank in IB.

there are 5 possible images (Graphic0, Graphic1, etc.)

For some reason it keeps displaying Graphic1.

I got a feeling I'm missing something simple. Can you help please?

This what i am using:

getCard=0;
 NSLog(@"begin showCard = %i",getCard);
 FlowCoverAppDelegate *mainDelegate = (FlowCoverAppDelegate *)[[UIApplication sharedApplication]delegate];
 getCard = mainDelegate.showCard;
 NSLog(@"showCard = %i",getCard);

 if (getCard = 0) {
     [popCard setImage:[UIImage imageNamed:@"Graphic0.jpg"]];
     popCard.contentMode = UIViewContentModeScaleAspectFit;
     return;
 }

Cheers Paul

+5  A: 

The issue with your code is the following:

You are assigning getCard to 0 in your if expression, change it to ==.

Also, if getCard is not a property of your object, you need to declare it as int getCard = 0;

What you should do:

Instead of writing 5 if statements, just write this one line:

[popCard setImage:[UIImage imageNamed: [ NSString stringWithFormat: @"Graphic%d.jpg", getCard ] ] ];
Jacob Relkin
that's why some prefer to write if (0 == getCard)
Vladimir
Thank you! That's the second time == caught me out.Vladmir - I really like that format. It'll help me remember.
Paul Sommers