tags:

views:

336

answers:

1

I have a UIView that displays an image depending on how well the user did on a level, then the user has the options to continue to the next level and once they are finished with that one the UIView displays again with an image depending on how well they did

I release the UIView after the user decides they want to go to the next level and inside the UIView I'm pretty sure I release everything once I'm finished with it but when the UIView is loaded for the second time the image from the first time is still there and the second image gets put on top of it so you see both images at the same time.

I'm not sure why this is happening like I said I'm pretty sure I release everything inside the UIView and then I release the UIView when the user is finished with it

I created the UIView with Interface Builder

Any help would be appreciated

//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];
A: 

I tried something similar just now, and in order to get two overlapping images, I had to call this twice:

medal =[[UIImageView alloc] initWithFrame:medalFrame]; medal.image = medalImage; [medalImage release]; [medal setNeedsDisplay];

[self addSubview:medal];

Can you check and see if you are doing that?

mahboudz
Technically is does get called twice after the first level it gets called for that level and then the levelComplete UIView is released so the user can play through level two, and then when level two in finshed levelComplete is called again and a medal is displayed...it seems that first instance of levelComplete isn't getting cleared out and I'm not quite sure why
Keeper
In order not to get two on top of each other, you should remove medal before you add then next with a different badge. Otherwise you create two UIImageViews and add them to the same view.
mahboudz
yeah I literally just figured out that I wasn't removing the Image before adding the second one, However what I'm unclear on now is why Dealloc is never getting called there is only one instance of levelComplete shouldn't dealloc get called when I removeFromSuperView?
Keeper