views:

113

answers:

1

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?

+3  A: 

Just use:

txtName.text = placeHolderName;

or

txtName.text = [NSString stringWithFormat:@"%@", placeHolderName];

In code you have now you accidentally use Comma operator that evaluates its first expression (txtName.text = @"%@"), discards the result and returns the 2nd (placeHolderName)

Vladimir