I have declared NSString with some string value in ViewdidLoad like..
int i=1;
strval=[NSString stringWithFormat:@"%03d",i];
strval=[NSString stringWithFormat:@"S%@",strval];
NSLog(@"Value %@",strval);
it gives correct result as S001, but when i print this same in IBAction like,
- (IBAction)stringvalue:(id)sender {
NSLog(@"Value %@",strval);
}
it gives unknown values each time.Sometimes it throws EXEC_BAD_ACCESS error.
Please help me..
Looks like you aren’t using ARC, so the string is being released the next time the autorelease pool drains. You need to explicitly
retainit inviewDidLoadand explicitlyreleaseit in your overwriddendeallocmethod:(I am assuming you’ve actually declared
strvalas an instance method).