开发者

iphone Development - data persistance UI

开发者 https://www.devze.com 2023-03-22 02:40 出处:网络
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.

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

0

精彩评论

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