我有一个UIView,根据用户在某个级别上的表现显示图像,然后用户可以选择继续到下一个级别,一旦完成了那个,UIView再次显示依赖于图像他们做得多好
我在用户决定要进入下一级并且在UIView内部之后释放UIView我很确定在完成它之后我会释放所有内容但是当第二次加载UIView时从第一次起仍然存在,第二个图像放在它上面,所以你可以同时看到两个图像。
我不确定为什么会这样,就像我说我很确定我在UIView中发布了所有内容然后在用户完成后释放UIView
我使用Interface Builder
创建了UIView任何帮助将不胜感激
//this is the code to access the UIView
-(void)DisplayStatsForLevel:(NSInteger)level ScoreEarned:(NSInteger)pScore NumberHit:(NSInteger)pNumberHit TotalTargets:(NSInteger)pTotalTargets MedalEarned:(NSInteger)pMedalEarned BulletsFired:(NSInteger)pBulletsFired
{
switch(level)
{
case 1:
[levelOne removeFromSuperview];
[levelOne release]; levelOne = nil;
[self.view addSubview:levelComplete];
[levelComplete SetupScreen:pScore NumberHit:pNumberHit TotalTargets:pTotalTargets MedalEarned:pMedalEarned BulletsFired:pBulletsFired];
break;
case 2:
[levelTwo removeFromSuperview];
[levelTwo release]; levelTwo = nil;
[self.view addSubview:levelComplete];
[levelComplete SetupScreen:pScore NumberHit:pNumberHit TotalTargets:pTotalTargets MedalEarned:pMedalEarned BulletsFired:pBulletsFired];
break;
default:
break;
}
}
//this is the code that releases the UIView
-(void)NextLevel:(NSInteger)nextLevel
{
switch (nextLevel)
{
case 2:
[levelComplete removeFromSuperview];
[levelComplete release]; levelComplete = nil;
[self.view addSubview:levelTwo];
[levelTwo SetupLevel];
break;
default:
break;
}
}
//this is the code that displays the image
switch (medalWon)
{
case 1:
medalImage = [UIImage imageNamed:@"Bronze.png"];
break;
case 2:
medalImage = [UIImage imageNamed:@"Silver.png"];
break;
case 3:
medalImage = [UIImage imageNamed:@"Gold.png"];
break;
case 4:
medalImage = [UIImage imageNamed:@"Platinum.png"];
break;
default:
break;
}
medal =[[UIImageView alloc] initWithFrame:medalFrame];
medal.image = medalImage;
[medalImage release];
[medal setNeedsDisplay];
[self addSubview:medal];
答案 0 :(得分:1)
我刚才尝试了类似的东西,为了获得两个重叠的图像,我不得不称之为两次:
medal = [[UIImageView alloc] initWithFrame:medalFrame]; medal.image = medalImage; [medalImage发布]; [medal setNeedsDisplay];
[self addSubview:medal];
你能检查一下你是否这样做吗?