无法setImage

时间:2010-01-20 11:11:17

标签: iphone cocoa-touch ios uiimageview

Noob Alert,

我正在尝试更改UIImageView中的图像。

popCard是指向UIImageView的IBOutlet - 在IB中是空白的。

有5种可能的图像(Graphic0,Graphic1等)

由于某种原因,它会一直显示Graphic1。

我感觉我错过了一些简单的事情。你能帮忙吗?

我正在使用的是:

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;
 }

干杯 保罗

1 个答案:

答案 0 :(得分:5)

您的代码存在以下问题

您要在getCard表达式中为0分配if,将其更改为==

此外,如果getCard不是您对象的属性,则需要将其声明为int getCard = 0;

你应该做什么

不要编写5个if语句,只需写下这一行:

[popCard setImage:[UIImage imageNamed: [ NSString stringWithFormat: @"Graphic%d.jpg", getCard ] ] ];