Reputation: 121
I am trying to save text data from my TextView. When my cell in an UITableView is clicked, it leads to the next UIViewController where my TextView is set. After writing a note there, going back to my first ViewController and then going back to the ViewController where my TextView is set, the note I wrote does not remain there. I have no idea how to save the data permanently there. I assume Core data or NSDefaults is necessary to do this, but do not know how to implement the code. I appreciate if you could give me the actual code.
Upvotes: 0
Views: 163
Reputation: 944
When you dismiss or pop the ViewController, the controller will destory. So use NSUserDefault is a good way to save text into sandbox.
When you exit the textView:
NSUserDefaults *saver = [NSUserDefaults standardUserDefaults];
[saver setObject:self.textView.text forKey:@"FirstTextKey"];
Then get into textView controller you want to see the text you have saved:
NSUserDefaults *saver = [NSUserDefaults standardUserDefaults];
NSString *firstText = [saver objectForKey:@"FirstTextKey"];
Upvotes: 1
Reputation: 10344
You can also check this to save and retrieve data from NSUserDefaults and you can implement this in your code when TextView end change method and also in back button press of your UIViewController class.
Upvotes: 0
Reputation: 132
Place the text in a NSString and store it in the view by using a property. Then implement NSCoding standard protocol and then when the back button is pressed archive it using NSKeyedArchiver and then when you again log on to same View...use NSKeyedUnarchiver
Upvotes: 0