views:

146

answers:

2

I am adding a UILabel as a subview to a UIView and sometime later I want to hide it. It is assigned to a variable but I don't think setting the variables property Hidden after it's been added to the view will work (well it doesn't seem to anyway).

Is there a way to loop through the subviews in a view and then find the one that has a specific tag or is of type UILabel that I could then remove?

A: 

You can use UIView's subviews property. It will contain a reference to the UILabel.

Having said that, you are probably not handling the UILabel variable correctly, since what you've described you're doing should work.

Pablo Santa Cruz
+3  A: 
[[containerView viewWithTag:kMyLabelTag] setHidden:YES];
drawnonward
It took me a while to get it working, I was too doing something wrong in the way I was putting the label on, I think I was putting 2 labels over each other so your code did work but i didn't visually see it. Is all good now though.
tarnfeld