Access the dynamically loaded Labels in UIScrolView

328 views Asked by At

I am working on an iPhonne app that requires me to dynamically add a UILabel to a UIScrollView on a specific action and then delete the selected label from the same view.

I am able to add the labels, but unable to access the labels added to delete. Once the labels are deleted the rest of them shall auto adjust in the view.

Can you please help me out in this.

thanks in advance!!.... :)

1

There are 1 answers

0
Jonathan. On BEST ANSWER

When you add the UILabel you need to set it's tag. Eg

[myLabel setTag:2]; //or set it to some dynamically produced integer

Then when you want to access the label again you do

UILabel *addedLabel = [myScrollView viewWithTag:2];

Then you can remove the label or do anything else you normally do

Don't use tags of 0 or 1 as they are the defaults and you should have to views with the same tag.