my problem is very simple (sorry my english, im speak spanish)
i have
NSString *ClaseUsuario;
AND
@property (strong, nonatomic) NSString *ClaseUsuario;
I have a method that changes the value of my variable
-(IBAction)setLabelEdad{
int val=(int)[botonEdad value];
if(val>0 && val<22){ClaseUsuario=@"C";}
if(val>=22 && val<35){ClaseUsuario=@"B";}
if(val>=35){ClaseUsuario=@"A";}
NSLog(ClaseUsuario);
}
but my problem is that when I call my variable from another method the answer is NULL
-(IBAction)VerOfertas{
NSLog(@"%@%@",@"Ofertas usario tipo: ",ClaseUsuario);
}
I need to save the value assigned by the above method, please help! and thank you very much
There are several things to fix here:
Use a leading lowercase letter for your property:
claseUsuario. This matters for KVC.Do not declare an ivar at all. Just use
(Note the leading underscore. There is seldom reason to explicitly declare an instance variable any more unless you’re writing for very old systems.)
Except in
initanddealloc, always use the accessor. So this should beself.claseUsuario = @"C";. This will ensure that memory management works correctly.Generally your
NSLogshould be of this form:Do not name your
IBActionwith a leadingset. This can confuse KVC because it looks like an accessor.The likely actual cause of your problem is that either
setLabelEdadis never called, or you clearclaseUsuariosomewhere else, or you are looking at the wrong object. Put a breakpoint insetLabelEdadto test these.