Is there a way to save the text within a UITextView using NSUserDefaults? When I use it for a UITextField it works just fine. Here is the code I use for a UITextField:
-(void)viewDidLoad {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *text1 = [defaults objectForKey:@"text1"];
textfield1.text = text1;
}
-(IBAction)saveButton {
[textfield1 resignFirstResponder];
NSString *text1 = [textfield1 text];
NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];
[myDefaults setObject:text1 forKey:@"text1"];
[myDefaults synchronize];
NSLog(@"Data Saved")
}
However, if I use this simple way to save for a UITextView instead of a UITextField the data within the view doesn’t save. Any suggestions?
The exact same code you used for UITextField should work for UITextView; the method
textworks for both.This code worked for me:
I’d guess that your problem lies in accessing your UITextView’s text. NSLog it, as I did above, and see if it’s as you expected.