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.
Asked
Active
Viewed 159 times
0
-
what do you mean by `actual code`? what you think here folks waiting for assignment like this? just do some home work and then come again with any hurdle. – Buntylm Dec 22 '15 at 04:54
-
refer this link help you http://code.tutsplus.com/tutorials/ios-sdk-working-with-nsuserdefaults--mobile-6039 – Dharmesh Dhorajiya Dec 22 '15 at 04:56
-
I mean, just any code that works for saving text data – Ryohei Arai Dec 22 '15 at 04:56
-
I think this will help you http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – ZHZ Dec 22 '15 at 04:59
-
But the thing is ... I do not know how to read Objective-C....., but I will try! Thanks you guys! – Ryohei Arai Dec 22 '15 at 05:03
3 Answers
1
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"];

ImWH
- 820
- 1
- 7
- 20
0
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

Shubham Chawla
- 132
- 1
- 10
0
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.

Community
- 1
- 1

Chetan Bhalara
- 10,326
- 6
- 32
- 51