开发者

Keeping variable values when the iPhone is shut-down?

开发者 https://www.devze.com 2023-03-10 18:47 出处:网络
开发者_开发问答Lets say i have an application which has three text-fields, and i can type whatever i want into them, lets also assume that i have a checkbox and a button. And if the button is tapped w
开发者_开发问答

Lets say i have an application which has three text-fields, and i can type whatever i want into them, lets also assume that i have a checkbox and a button. And if the button is tapped while the checkbox is checked, the nsstring values in these textfields should get saved somehow. Lets say i power down my iPhone and restarted it, opened the app once again and wanted those values to be in their respective textfields.

How does one do this?

Is this a case for NSUserDefaults or something for Apple's own Keychain API to handle?

Cheers.

Edit: We used local declarations when setting and getting the values of the NSUserDefaults, which of course, doesnt work. It works perfectly now...


Yes you can make use of NSUserDefaults


Integrate a sqlite3 database into ur app.. save the textfields value in an array and sav it in the database. On starting of the apps just load from the database and retrieve the top most array and show the values back as output.. Hope it helps.. I am new also.. but cant think of anything else if u want to restart ur whole phone and still wants the fields to be filled.


Use NSUserDefaults for stuff that doesn't need to be stored securely and Keychain if it does.


You can use the NSUserDefaults or a PList or a database to save the content. Example is given below:-

[[NSUserDefaults standardUserDefaults] setObject:@"Jayahari" forKey:@"userName"];

PList can be used for archiving, serilizing. Database also can be used for same purpose.

0

精彩评论

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