Objective C iPhone save text
How is it possible to save text from a text field when the user quit's the app then when the user re opens the app the text appears back in the same text box, can this be done with out a save button? What code is needed for the text to be saved and what action is needed for doing this when the app is opened?
Thanks, David开发者_运维知识库
Yes. If the string is short, you can save the string using
[[NSUserDefaults standardUserDefaults] setObject:theText forKey:@"file"];
and retrieve it with
return [[NSUserDefaults standardUserDefaults] stringForKey:@"file"];
If it is long, you can save it as a file.
To read the string at start up, use the code above in your app delegate's -applicationDidFinishLaunching:
. Similarly, put the saving code in -applicationWillTerminate:
.
精彩评论