Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bbrosemer

macrumors 6502a
Original poster
Jan 28, 2006
639
3
Code:
- (void)viewWillAppear:(BOOL)animated {
	
	int i = 0;
	int y = [xValues count];
	for(i; i < y; i++)
	{
		UIImageView *tempView;
		int xHolder = [[xValues objectAtIndex:i]intValue];
		int yHolder = [[yValues objectAtIndex:i]intValue];
		if((i+5)>=y)
		{
			tempView = [self newPieceViewWithImageNamed:@"newHits.png" atPostion:CGPointMake((xHolder),(yHolder))];
		}
		else{
			tempView = [self newPieceViewWithImageNamed:@"Baseball.png" atPostion:CGPointMake((xHolder),(yHolder))];
			tempView.alpha = .30;
		}
		[self.view addSubview:tempView];	
	}
	
	firstPieceView = [self newPieceViewWithImageNamed:@"Baseball.png" atPostion:CGPointMake(290.,380)];
	[self.view addSubview:firstPieceView];
}

Is there anyway when I leave the view to release all instances of the subviews ... there should be one but I don't know of what to call if I basically just want to start the view over with a clean slate the next time I call it ...
 
Code:
- (void)viewWillAppear:(BOOL)animated {
	
	int i = 0;
	int y = [xValues count];
	for(i; i < y; i++)
	{
		UIImageView *tempView;
		int xHolder = [[xValues objectAtIndex:i]intValue];
		int yHolder = [[yValues objectAtIndex:i]intValue];
		if((i+5)>=y)
		{
			tempView = [self newPieceViewWithImageNamed:@"newHits.png" atPostion:CGPointMake((xHolder),(yHolder))];
		}
		else{
			tempView = [self newPieceViewWithImageNamed:@"Baseball.png" atPostion:CGPointMake((xHolder),(yHolder))];
			tempView.alpha = .30;
		}
		[self.view addSubview:tempView];	
	}
	
	firstPieceView = [self newPieceViewWithImageNamed:@"Baseball.png" atPostion:CGPointMake(290.,380)];
	[self.view addSubview:firstPieceView];
}

Is there anyway when I leave the view to release all instances of the subviews ... there should be one but I don't know of what to call if I basically just want to start the view over with a clean slate the next time I call it ...

int i,j;

j = [[self.view subviews] count] - 1;

for (i = j; i >=0; i--)
{
[[[self.view subviews] objectAtIndex:i] removeFromSuperview];
}
 
int i,j;

j = [[self.view subviews] count] - 1;

for (i = j; i >=0; i--)
{
[[[self.view subviews] objectAtIndex:i] removeFromSuperview];
}

So self.view subviews removefromsyoerview can remove any generic subview?
 
So self.view subviews removefromsyoerview can remove any generic subview?

Yup. "subviews" returns an array of the subviews for a given view. ghayenga's code snippet iterates through all of these subviews and removes them from the view. Here's some shorthand that does the same:

Code:
for (UIVIew *view in [self.view subviews]) {
	[view removeFromSuperview];
}
 
So basically you 2 are my heros ... I was thinking apple really needed a way to remove all subviews ... and then I get my answer that subviews returns an array of subviews .... that is beautiful
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.