Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure I completely follow, so correct me if I'm misunderstanding. Every time you call this function, you are adding a number of new labels. So if you call this function the second time, assuming 'count', 'ycord', 'width', and 'height' correspond with the values that the first call had, you are obviously adding a second group of labels in the same place as the first ones which are now directly on top of one another. You are not "overriding" the old labels, you are placing a second group directly ontop of the old ones.</p> <p>Calling "release" on each label, only means you are decreasing the retainCount by 1. This number is used for memory management only. This means if you now remove the labels from the view the memory is released.</p> <pre><code>CGRect lblframe = CGRectMake(10.0, ycord, 200.0, 20.0); UILabel *label = [[UILabel alloc] initWithFrame:lblframe]; NSLog(@"retainCount of label: %d", [label reatinCount]); // will print "1" since you called alloc [self.view addSubview:label]; NSLog(@"retainCount of label: %d", [label reatinCount]); // will print "2" since adding to subview increases retaincount by one [label release]; NSLog(@"retainCount of label: %d", [label reatinCount]); // will print "1" since you released [label removeFromSuperview]; // will decrease retainCount of label to "0" and therefore free the memory </code></pre> <p>so say you wanted to remove the previously created labels from the view, you would have to do so. Either keep a reference to each of them and call "removeFromSuperview" on each of them.</p> <p>If the only thing in the view where you're adding the labels, you can also just remove every subview that was added to it like so:</p> <pre><code>// 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&lt;[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]; } </code></pre> <p>I hope this helped, but providing further info on what you're trying to do may make it easier to help you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload