Search code examples
iosios4

ios get label from tag number


I want to get a label's attributes from self so I tried:

UILabel *label = (UILabel *)[self viewWithTag:1];

But all I got was an empty UILabel instead of the label I was looking for. What is correct way to do this.


Solution

  • So I figured out what I was doing wrong. Obviously

     UILabel *label = (UILabel *)[self viewWithTag:1];
    

    creates a pointer to the instance of my label with tag 1. This does actually work. What doesn't work and why I was having problems came from trying to release label. Releasing label is the same as release [self viewWithTag:1] which is not what I was trying to do.