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;
}
干杯 保罗
答案 0 :(得分:5)
您的代码存在以下问题:
您要在getCard
表达式中为0
分配if
,将其更改为==
。
此外,如果getCard
不是您对象的属性,则需要将其声明为int getCard = 0;
你应该做什么:
不要编写5个if
语句,只需写下这一行:
[popCard setImage:[UIImage imageNamed: [ NSString stringWithFormat: @"Graphic%d.jpg", getCard ] ] ];