Question

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

} 
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top