I have a UILabel that is modified while using my a开发者_StackOverflow中文版pp. I want the text of this UILabel to be saved even after I close the app.
What's the easiest way for doing this?
Save the content when the app is about to quit.
- (void)applicationWillTerminate:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults] setObject:label.text forKey:@"label"];
}
And when you create the label, use the saved text.
label.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"label"];
NSUserDefaults will help you with this !
Watch this tutorial on how to use NSUserDefaults for storing/ saving data - Save Data In Your iPhone App Using NSUserDefaults Tutorial
精彩评论