views:

238

answers:

2

Is there a way to remember what the user put into a UITextField and have it displayed the next time they come to that UITextField? i.e. - have them input their name the first time they come to the "Name" UITextField but have that name already displayed in that field the next time they come across that UITextField?

I want the name to still be editable if they come back to the UITextField, but inputted nonetheless in case they don't need to change it the second time around.

A: 

If you want the UITextField to keep it's data between launches of your app, you will need to look into data persistence.

If you just want it to be the same if they navigate back to it from another view, simply leave the UITextField allocated, or better yet, store the data in an object reserved for data storage, not presentation, and then load the existing name from that every time you allocate the UITextView.

Chris Cooper
I stopped deallocating the variables and it seems to work when switching between certain views but not others. What did you mean by load the existing name when allocating the UITextView??
Rob
As in have an object called `state` or something, containing an `NSString`, which you assign whenever the user edits the text field. Then write that to a file when the app quits. When you open the app again, load that value from the file back into `state`, then initialize your `UITextfield` from the string in `state`. It is sort of complex for this simple case, but it makes it easier if you need to store more complex data and don't want to distribute your application's data.
Chris Cooper