Hey!
I am making an app that has 8 UITextFields and I want it so when I click a UIButton, it will save the data in all 8 of the text fields. So if they save it, they can come back later and see all the info they have put in the UITextFields. Please help me! I looked at code from another thread and this is what it said:
Quote:
This is pretty easy to do. Let's say you have a UITextField that you want people to enter info into and then save. In your header file (.h):
Code:
IBOutlet UITextField *myTextField;
- (IBAction)updateInfo id)sender;
Open your view controller .xib file. It will open. In Interface Builder, drag the text field into the view. Then, right click or contol-click "File's Owner" and drag the line to your text field. Select myTextField (this is the name of the text field we declared in the header file.) Then drag a button into the view. Change the button's title to something like Save.
Then go into your implementation (.m):
Code:
- (IBAction)updateInfo id)sender{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:myTextField.text forKey:@"userInfo"];
[defaults synchronize];
}
Here, when the user hits the button, the text they entered into the text field is saved into the user defaults. Good place to store random info. What about when you need to retrieve this info?
Code:
[defaults valueForKey:@"userInfo"];
|
I get all of it and where to put it. But the only part I don't get is the retrieving info part? My question about that is, where do I put that piece of code?