开发者

Objective C iPhone save text

开发者 https://www.devze.com 2022-12-26 05:05 出处:网络
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?

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:.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号