Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 08-27-2009, 01:33 PM   #10 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
jsd is on a distinguished road
Default

Quote:
Originally Posted by Dutch View Post
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.
jsd is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,176
Threads: 93,917
Posts: 402,136
Top Poster: BrianSlick (7,966)
Welcome to our newest member, spiketmr
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:59 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.