Hello,
You might want to use %i instead of %@. I don't know if that would work, but try it.
Also, you might want to use code tags when posting code, with [ code] and [ /code] without the spaces.
Hope that helps.
Sorry, it was a typo. I use %i, but the problem seems to be the NSString themself. The compiler didn't translate it in the labelname respectively cann't use it. Thanks for reply.
You have an array full of labels now... and can iterate through them just like above, redeeming its object with [array objectAtIndex: ]
What exactly are you doing ? How do you create the labels ?
I am creating a clock.app as my first iphone project. The labels are already created at Interface Builder. Now I want to change the color of the current minute... Therefore I use a "for... loop" and want to address the labels color for example.
Thanks for reply.
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.
If you consider "lightweight" to be the same as "has the potential to make your app very slow"...
Obviously, any programmer with any ability to see these things would have to realize that if you had 752,945 subViews on the searched form, the tag approach would be less than advisable. The right way to do this as you've said is to create an array and fill 'er up. I was just trying to demonstrate how you can not call an item by a dynamic name in the way the OP was trying.
If he has a subview filled only with buttons wouldn't the performance be the same of the array without the need to create it?
But in fact I didn't stop to think about the inner working of viewWithTag and the very bad scenarios that could happen
If he has a subview filled only with buttons wouldn't the performance be the same of the array without the need to create it?
But in fact I didn't stop to think about the inner working of viewWithTag and the very bad scenarios that could happen
Actually, using an array you can access the objects directly giving its array index to [array objectAtIndex:...].... This eliminates the need to FOR loop through them all. Again, if we're talking about 5, 10, 25 objects either is fine - but for larger numbers I would use the array.
Ouch, now I see what you mean.
I assumed viewWithTag was some magical hash based search when it actually sweeps each subview to find the first matching tag.