开发者

Can't setImage

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


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 ] ] ];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜