I have two views.In One view when i click on custom button it goes into second view,In that i have text view and that data must store in temperary memory so i used following code:
NSString *myString=txtvNote.text;
[txtvNote setText:@""];
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
if (standardUserDefaults) {
[standardUserDefaults setObject:myString forKey:@"note"];
[standardUserDefaults synchronize];
}
and when i go back on 1st view by clicking on the add button it will save into database for that i used following code:
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *val = nil;
if (standardUserDefaults)
val = [standardUserDefaults objectForKey:@"note"];
NSLog(@"Note::%@",val);
and then pass this value in insert query.
Now my problem is when i left that value blank,it takes the value which is inserted before.
myStringis a pointer to the text intxtvNote. So if you set that text to @”” then myString will be empty as well. To preserve the value of txtvNote at the time of assignment usecopyor reset the text after saving it: