__NSCFString setHidden: unrecognized selector sent to instance

1.2k views Asked by At

I have got some UILabels which have been declared as property and synthesized. I am hiding those labels in viewDidLoad. After some calculations, when I try to unhide them using hidden property, app crashes with error mentioned in the subject. I tried NSLog to know if it has been deallocated or not, but it is showing me fine values of labels. Please can someone help me that where is memory management problem while I am accessing it normally. Thanks.

Showing some code for reference:

In .h file:

@interface abc : UIViewController{
   UILabel *value;
}

@property(nonatomic,retain) IBOutlet UILabel *value;

In .m file:

@synthesize value;

-(void) viewDidLoad
{
value.hidden = YES;
}

-(IBAction) calculate:(id)sender

//On some button click, assign some value to label and unhide it

NSLog(@"%@",value); //perfectly OK
value.hidden = NO; //throws exception here

} 
1

There are 1 answers

1
iDev On BEST ANSWER

The error is because the label is getting released and getting assigned to NSString. Check how are you setting value to the label. You should be assigning an NSString to UILabel which causes it to throw this error when hidden property is called on value param.