I'm not sure that I am fully following, so correct me if I do not understand. Each time you call this function, you add a few new labels. Therefore, if you call this function a second time, counting "count", "ycord", "width" and "height", correspond to the values ββthat the first call had, you obviously add a second group of labels in the same place like the first ones that are now directly above each other. You do not "redefine" the old labels, you put the second group directly on top of the old ones.
Calling "release" on each label means that you decrease the value of keepCount by 1. This number is used only for memory management. This means that now you remove the shortcuts from the view in which the memory is issued.
CGRect lblframe = CGRectMake(10.0, ycord, 200.0, 20.0); UILabel *label = [[UILabel alloc] initWithFrame:lblframe]; NSLog(@"retainCount of label: %d", [label reatinCount]);
so say you wanted to remove previously created labels from the view, you have to do it. Or keep a link to each of them, and call "removeFromSuperview" for each of them.
If in the view in which you add tags, you can simply delete each subheading that has been added to it, for example:
// remove old labels for (UILabel *aLabel in [self.view subviews]) [aLabel removeFromSuperview]; NSArray *myArray = [NSArray arrayWithObjects:@"I", @"II", @"III", @"IV", nil]; for (int i=0; i<[myArray count]; i++) { float ycord = i*40.0; CGRect lblframe = CGRectMake(10.0, ycord, 200.0, 20.0); UILabel *label = [[UILabel alloc] initWithFrame:lblframe]; label.backgroundColor = [UIColor blackColor]; label.font = [UIFont systemFontOfSize:17]; label.textAlignment = UITextAlignmentCenter; label.textColor = [UIColor colorWithRed:(188/255.f) green:(149/255.f) blue:(88/255.f) alpha:1.0];; label.text = [myArray objectAtIndex:i]; [self.view addSubview:label]; [label release]; }
I hope this helps, but providing more information about what you are trying to do may help you.