无法setImage

1 iphone cocoa-touch uiimageview ios

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;
 }
Run Code Online (Sandbox Code Playgroud)

干杯保罗

Jac*_*kin 5

您的代码存在以下问题:

要分配getCard0你的if表情,将其更改为==.

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

你应该做什么:

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

[popCard setImage:[UIImage imageNamed: [ NSString stringWithFormat: @"Graphic%d.jpg", getCard ] ] ];
Run Code Online (Sandbox Code Playgroud)