iPhone inputting NSUserDefaults into a UITextField
Posted
by Rob
on Stack Overflow
See other posts from Stack Overflow
or by Rob
Published on 2010-05-11T23:42:47Z
Indexed on
2010/05/11
23:44 UTC
Read the original article
Hit count: 228
I am writing a program where I where the first time a user runs it - they will have to fill out about 10 different UITextFields. I am trying to save the fields so that on subsequent runs of the program that whatever they previously put will already be displayed in those UITextFields so the wont have to re-input it in - unless they want to edit something in which case they still have that option. I think that I have figured out a good way to save the strings using NSUserDefaults but now I am trying to figure out how to have those fields populate a UITextField - it doesnt seem as easy as if they were UILabels. This is the route I am attempting:
// in the viewDidLoad portion.
NSUserDefaults *userData = [NSUserDefaults standardUserDefaults]; //Hooks.
NSString *placeHolderName = [userData stringForKey:@"name"];
txtName.text = @"%@", placeHolderName;
When I do this, it simply displays the '%@' in the textfields. I want whatever variable being held by placeHolderName to be automatically put into that UITextField. Is this possible?
© Stack Overflow or respective owner