Quote:
Originally Posted by Dutch
Your best bet is to assign each label a unique tag (which must be an integer).
Code:
for (NSInteger i=0; i<50; i++){
UILabel *lbl=[[UILabel alloc] initWithFrame:CGRect(0,20*i, 100, 20)];
[lbl setTag:i];
[lbl setText:[NSString stringWithFormat:@"Label #%d", i]];
[self.view addSubview:lbl];
[lbl release];
}
This will give us 50 labels all with tags (0-49). Then later on, when you want to access the label, do something like this...
|
This has the potential to get you into trouble because viewWithTag has to search through all the subviews looking for one that matches. If you're doing it a lot, it's a real performance hit.
Use an array or dictionary, as others have mentioned already in this thread.