I’m having a problem with labels. I have a couple of labels that I need to change with help of tags. I do this in my code, but it gives an exception
-[UIView setText:]: unrecognized selector sent to instance
This is my code:
UILabel *label = (UILabel *)[self.view viewWithTag:0];
label.text = @"empty";
Any help appreciated, thanks.
Every view’s tag is default to 0.
Your
viewWithTagwill return yourself.view. So you will get aUIViewinstead of aUILabeland your app will crash. SeeviewWithTag‘s definition:So the solution for you is you need to specify unique
tagfor every label. And then useviewWithTag:and give the tag you specified.