I saw a couple of examples but I cannot figure out what's going wrong when trying to save my text field input and reload it when restarting the app.
I have something like this in my .m file (.h file only has a <UITextViewDelegate>);
#implementation C4WorkSpace{
UITextView *textField;
C4Button *okButton;
C4Label *savedText;
}
-(void)setup {
//add text field
CGRect textViewFrame = CGRectMake(20.0f, 20, self.canvas.width-40, 124.0f);
textField = [[UITextView alloc] initWithFrame:textViewFrame];
textField.returnKeyType = UIReturnKeyDone;
[textField becomeFirstResponder];
textField.delegate = self;
//textField.hidden=true;
[self.view addSubview:textField];
okButton=[C4Button buttonWithType:ROUNDEDRECT];
[okButton setTitle:#"Save" forState:NORMAL];
okButton.center=self.canvas.center;
[self.canvas addUIElement:okButton];
[okButton runMethod:#"saveDefault" target:self forEvent:TOUCHUPINSIDE];
savedText=[C4Label labelWithText:#"default"];
savedText.center=CGPointMake(self.canvas.center.x, self.canvas.center.y+40);
[self.canvas addLabel:savedText];
}
-(void)saveDefault{
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:textField.text forKey:#"userName"];
[defaults synchronize];
C4Log(#"defaults: %#",defaults);
C4Log(#"defaults: %#", [defaults objectForKey:#"userName"]);
savedText.text=textField.text;
}
-(void)viewDidLoad{
NSMutableString *text=[[NSUserDefaults standardUserDefaults] objectForKey:#"userName"];
C4Log(#"loadedText:%s", text);
textField.text=text;
savedText.text=text;
}
#end
I'm not sure what exactly is going wrong, but when I restart the app the loadedText is always: "¯8*:å". Doesn't matter what I saved.
I found the easiest solution is to set in
ViewDidLoad
text=[[NSUserDefaults standardUserDefaults] objectForKey:#"userName"];
and in setup
if (text!=nil) {
textField.text=text;
}
Where does Setup method is call ? I think in viewDidLoad you initialize, but setup method called earlier.
You don't save this info,so button don't recognizer or load info and set text before initialization.
in setup method load info
UItextView *k = [UItextView alloc] init];
k.text = [[NSUserDefaults standardUserDefaults] objectForKey:#"userName"];
and take a look what will be.
UPDATE:
That's wrong;
[c4workspace loadInfoFromDefaults];
[c4workspace alloc]init]; (calls viedidload method with load info)
You need
[c4workspace alloc]init];
[c4workspace loadInfoFromDefaults];
Please post code where you create c4WorkSpace object.
UPDATE 2:
-(void)setup {
//add text field
CGRect textViewFrame = CGRectMake(20.0f, 20, self.canvas.width-40, 124.0f);
textField = [[UITextView alloc] initWithFrame:textViewFrame];
textField.returnKeyType = UIReturnKeyDone;
[textField becomeFirstResponder];
textField.delegate = self;
//textField.hidden=true;
[self.view addSubview:textField];
okButton=[C4Button buttonWithType:ROUNDEDRECT];
[okButton setTitle:#"Save" forState:NORMAL];
okButton.center=self.canvas.center;
[self.canvas addUIElement:okButton];
[okButton runMethod:#"saveDefault" target:self forEvent:TOUCHUPINSIDE];
savedText=[C4Label labelWithText:#"default"];
savedText.center=CGPointMake(self.canvas.center.x, self.canvas.center.y+40);
[self.canvas addLabel:savedText];
}
- (void) setTextView
{
textField.text=[[NSUserDefaults standardUserDefaults] objectForKey:#"userName"];
savedText.text=[[NSUserDefaults standardUserDefaults] objectForKey:#"userName"];
}
So you call this like:
C4WorkSpace *c4 = [C4WorkSpace alloc] init];
[c4 setup]
[c4 setTextView];
Related
i saved results from API to nsmutabledictionary. In this API is paging after 15 results (1,2,3, etc).
I need to fill resultDictionary with results from API.
My code:
self.resultDictionary = [[NSDictionary alloc] init];
self.resultDictionary = [self.api sendDataViaPostAndFormDataWithTwoParameters:#"email" with:[[NSUserDefaults standardUserDefaults] valueForKey:#"email"] parameterTwo:#"heslo" with:[[NSUserDefaults standardUserDefaults] valueForKey:#"heslo"] onUrl:[NSString stringWithFormat:#"http://***", [[NSUserDefaults standardUserDefaults] valueForKey:#"id"], [[NSUserDefaults standardUserDefaults] valueForKey:#"token"], page] withMethod:#"POST" success:^(BOOL success) {
} failure:^(NSString *fail) {
NSLog(#"%#", fail);
}];
It works fine - it shows 15 results. But, when i scroll down in tableview and after 15 index load next page in api, it shows next 15 results. I need to join both (30results / old and new).
I tried add entries... but no effect.
Could you help me please?
edit:
my rest of code with edit from Ashish
#implementation testingTableViewController {
NSMutableDictionary * resultDictionary;
}
-(void)reloadData:(int)page {
// set selected NO
if ([[NSUserDefaults standardUserDefaults] valueForKey:#"id"] == NULL) {
loginViewController *login = [[loginViewController alloc] init];
login.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:login animated:NO];
} else {
SHOW_NAVIGATION_BAR
self.api = [[API alloc] init];
self.temp = [self.api sendDataViaPostAndFormDataWithTwoParameters:#"email" with:[[NSUserDefaults standardUserDefaults] valueForKey:#"email"] parameterTwo:#"heslo" with:[[NSUserDefaults standardUserDefaults] valueForKey:#"heslo"] onUrl:[NSString stringWithFormat:#"http://*****/=&page=%d", [[NSUserDefaults standardUserDefaults] valueForKey:#"id"], [[NSUserDefaults standardUserDefaults] valueForKey:#"token"], page] withMethod:#"POST" success:^(BOOL success) {
NSLog(#"OK načteno");
} failure:^(NSString *fail) {
NSLog(#"%#", fail);
}];
}
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
resultDictionary = [NSMutableDictionary dictionary];
self.temp = [[NSDictionary alloc] init];
[self reloadData:1];
[self.tableView reloadData];
[self.tableView setNeedsLayout];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[TableViewCell class] forCellReuseIdentifier:#"cell"];
self.chatButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.commentButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *commentButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
commentButton.frame = CGRectMake(15, 0, 20, 20);
[commentButton setImage:[UIImage imageNamed:#"chat"] forState:UIControlStateNormal];
[commentButton addTarget:self action:#selector(page1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:commentButton];
UIButton *chatButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
chatButton.frame = CGRectMake(65, 0, 20, 20);
[chatButton setImage:[UIImage imageNamed:#"like"] forState:UIControlStateNormal];
[chatButton addTarget:self action:#selector(page2) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:chatButton];
}
-(void)page1 {
[self reloadData:1];
[resultDictionary addEntriesFromDictionary:self.temp];
[self.tableView reloadData];
}
-(void)page2 {
[self reloadData:2];
[resultDictionary addEntriesFromDictionary:self.temp];
[self.tableView reloadData];
}
When click at first button, result is 15, if i again click on first button, result is still 15 instead 30
Thank you for any response
As per your code
self.resultDictionary = [[NSDictionary alloc] init];
self.resultDictionary = [self.api sendDataViaPostAndFormDataWithTwoParameters:#"email" with:[[NSUserDefaults standardUserDefaults] valueForKey:#"email"] parameterTwo:#"heslo" with:[[NSUserDefaults standardUserDefaults] valueForKey:#"heslo"] onUrl:[NSString stringWithFormat:#"http://***", [[NSUserDefaults standardUserDefaults] valueForKey:#"id"], [[NSUserDefaults standardUserDefaults] valueForKey:#"token"], page] withMethod:#"POST" success:^(BOOL success) {
} failure:^(NSString *fail) {
NSLog(#"%#", fail);
}];
You are not using NSMutableDictionary. Create instance of NSMutableDictionary at top of the class.
NSMutableDictionary * resultDictionary;
Initialize it in viewDidLoad method
self.resultDictionary = [NSMutableDictionary dictionary];
Finally in your code for fetching result form server.
NSDictionary *tempDict = [self.api sendDataViaPostAndFormDataWithTwoParameters:#"email" with:[[NSUserDefaults standardUserDefaults] valueForKey:#"email"] parameterTwo:#"heslo" with:[[NSUserDefaults standardUserDefaults] valueForKey:#"heslo"] onUrl:[NSString stringWithFormat:#"http://***", [[NSUserDefaults standardUserDefaults] valueForKey:#"id"], [[NSUserDefaults standardUserDefaults] valueForKey:#"token"], page] withMethod:#"POST" success:^(BOOL success) {
[self.resultDictionary addEntriesFromDictionary:tempDict];
} failure:^(NSString *fail) {
NSLog(#"%#", fail);
}];
I got a UITextField as subview.
- (void)viewDidLoad {
[super viewDidLoad];
textField = [[UITextField alloc] initWithFrame:CGRectMake(21, 21, 159, 37)];
textField.borderStyle = UITextBorderStyleNone;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = #"name";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.textColor = [UIColor whiteColor];
textField.keyboardAppearance = UIKeyboardAppearanceDark;
textField.delegate = (id) self;
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
[textField addTarget:self action:#selector(saveData:) forControlEvents:UIControlEventEditingDidEnd];
[self.view addSubview:textField];
}
-(void)saveData:(id)sender {
NSString *savestring = textField.text;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savestring forKey:#"savedstring"];
[defaults synchronize];
}
To load the data (viewDidLoad)
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *loadstring = [defaults objectForKey:#"savedstring"];
[textField setText:loadstring];
Now the problem is that it doesn't save and load the text of the UITextField.
First you need to enter some string in the Textfield and press return key, so that it will get a chance to call your "saveData" method and store the value in the NSUserDefaults. Just check all the values.
I found a solution:
textField.text = [defaults objectForKey:#"savedstring"];
Thanks everyone for your answers
"addSubview" after this method write to load the data method...
[self.view addSubview:textField];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *loadstring = [defaults objectForKey:#"savedstring"];
[textField setText:loadstring];
So in my app I'm using a Action sheet which displays which animations to use. Everything is implemented, however, I'm having trouble using user defaults to save the selected row and then pass that along to the rest of my code. I've used user defaults before on UISwitch, but this is different I suppose.
The portion I'm using is a UITableView. in the didselectrow:
//Animation Picker
[tableView deselectRowAtIndexPath:indexPath animated:NO];
NSString *actionSheetTitle = #"Choose your style.";
BlockActionSheet *sheet = [BlockActionSheet sheetWithTitle:actionSheetTitle];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[sheet addButtonWithTitle:#"Zoom Out" block:^{
[cell.textLabel setText:[NSString stringWithFormat:#"Animation Style: Zoom Out"]];
//User Defaults
[prefs setObject:#"Zoom Out" forKey:#"Zoom"];
cellTitle = #"Zoom Out";
}];
[sheet addButtonWithTitle:#"Drop In" block:^{
[cell.textLabel setText:[NSString stringWithFormat:#"Animation Style: Drop In"]];
//User Defaults
[prefs setObject:#"Drop In" forKey:#"Drop"];
cellTitle = #"Drop In";
}];
[sheet setDestructiveButtonWithTitle:#"Cancel" block:nil];
[sheet showInView:self.view];
[prefs synchronize];
[tableView reloadData];
Which should send the info to use the proper animationController:
-(void)infoButtonAction:(id)sender {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults synchronize];
if ([userDefaults stringForKey:#"Zoom"]) {
AppInfoViewController * info = [[AppInfoViewController alloc] init];
UINavigationController *vc = [[UINavigationController alloc] initWithRootViewController:info];
self.animationController = [[ZoomAnimationController alloc] init];
vc.transitioningDelegate = self;
[self presentViewController:vc animated:YES completion:nil];
[info release];
}
else if ([userDefaults stringForKey:#"Drop"]) {
AppInfoViewController * info = [[AppInfoViewController alloc] init];
UINavigationController *vc = [[UINavigationController alloc] initWithRootViewController:info];
self.animationController = [[DropAnimationController alloc] init];
vc.transitioningDelegate = self;
[self presentViewController:vc animated:YES completion:nil];
[info release];
}
NSLog(#"App Info");
}
Also should update the cell displaying which animationController was selected:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs synchronize];
[cell.textLabel setText:[NSString stringWithFormat:#"Animation Style:"]];
if ([prefs stringForKey:#"Zoom"]){
[cell.textLabel setText:[NSString stringWithFormat:#"Animation Style: Zoom Out"]];
}
else if ([prefs stringForKey:#"Drop"]) {
[cell.textLabel setText:[NSString stringWithFormat:#"Animation Style: Drop In"]];
}
UIView *animation = [[UIView alloc] initWithFrame:cell.frame];
animation.backgroundColor = [UIColor colorWithRed:0.176 green:0.176 blue:0.176 alpha:1];
cell.backgroundView = animation;
However, nothing is getting saved. What am I missing?
Thank you for any help.
UPDATE: 1/3
I managed to get everything working with the updated code above. The only thing now is it won't save the style I choose. If I choose Drop In, and re open the table, it reverts back to Zoom Out. How can I fix this?
Take one String object that
NSString *OneString = [NSString stringWithFormat: selectedValue];
and Use that OneString in if condition and rest of the code.
In the start screen of my app you are able to choose language between English and Swedish by clicking on either the flag of UK or Sweden.
The problem is that the ViewDidLoad does not recognize changes in the NSUserDefaults when you click a button. But when you restart the app, the language is the latest flag you clicked! So it saves the NSUserDefault but it only loads it the first time in ViewDidLoad..
When you click the English flag, sprakval sets to 0, and if you click the swedish flag, sprakval sets to 1. When you click a flag, it changes to a image with a tick icon in front of the flag.
Code:
-(IBAction) sprakEN
{
sprakval=0;
NSUserDefaults *sprakvalet = [NSUserDefaults standardUserDefaults];
[sprakvalet setInteger:sprakval forKey:#"Sprak "];
[sprakvalet synchronize];
[super viewDidLoad];
}
-(IBAction) sprakSE
{
sprakval=1;
NSUserDefaults *sprakvalet = [NSUserDefaults standardUserDefaults];
[sprakvalet setInteger:sprakval forKey:#"Sprak "];
[sprakvalet synchronize];
[super viewDidLoad];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSUserDefaults *sprakvalet = [NSUserDefaults standardUserDefaults];
sprakval2 = [sprakvalet integerForKey:#"Sprak "];
if (sprakval2==0)
{
spraklabel.text = [NSString stringWithFormat:#"Language:"];
[lhb setTitle:#"english" forState:UIControlStateNormal];
[hlb setTitle:#"english" forState:UIControlStateNormal];
[fhb setTitle:#"english." forState:UIControlStateNormal];
[blandatb setTitle:#"english.." forState:UIControlStateNormal];
UIImage *encheck = [UIImage imageNamed:#"United_Kingdomchecked.png"];
[enbutton setImage:encheck forState:UIControlStateNormal];
UIImage *seuncheck = [UIImage imageNamed:#"Sweden.png"];
[sebutton setImage:seuncheck forState:UIControlStateNormal];
self.title = #"Game";
}
else if(sprakval2==1)
{
spraklabel.text = [NSString stringWithFormat:#"Språk:"];
[lhb setTitle:#"swedish" forState:UIControlStateNormal];
[hlb setTitle:#"swedish" forState:UIControlStateNormal];
[flb setTitle:#"swedish" forState:UIControlStateNormal];
[fhb setTitle:#"swedish" forState:UIControlStateNormal];
[blandatb setTitle:#"swedish" forState:UIControlStateNormal];
self.title = #"Spel";
UIImage *secheck = [UIImage imageNamed:#"Swedenchecked.png"];
[sebutton setImage:secheck forState:UIControlStateNormal];
UIImage *enuncheck = [UIImage imageNamed:#"United_Kingdom.png"];
[enbutton setImage:enuncheck forState:UIControlStateNormal];
}
// Do any additional setup after loading the view, typically from a nib.
}
This is because you are calling ViewDidload method through its super class in -(IBAction) sprakSE
and -(IBAction) sprakEN
methods. So replace
[super viewDidLoad]; with
[self viewDidLoad]; in both methods. It will work properly.
Hope it helps you.
viewDidLoad is a method invoked after view has been loaded from nib file. You are not supposed to call it manually.
If you have written the code to refresh the controls in viewDidLoad move that into a different method and invoke that method from your button event handler.
- (void)adjustControlsForLanguage
{
NSUserDefaults *sprakvalet = [NSUserDefaults standardUserDefaults];
sprakval2 = [sprakvalet integerForKey:#"Sprak "];
if (sprakval2==0)
{
spraklabel.text = [NSString stringWithFormat:#"Language:"];
[lhb setTitle:#"english" forState:UIControlStateNormal];
[hlb setTitle:#"english" forState:UIControlStateNormal];
[fhb setTitle:#"english." forState:UIControlStateNormal];
[blandatb setTitle:#"english.." forState:UIControlStateNormal];
UIImage *encheck = [UIImage imageNamed:#"United_Kingdomchecked.png"];
[enbutton setImage:encheck forState:UIControlStateNormal];
UIImage *seuncheck = [UIImage imageNamed:#"Sweden.png"];
[sebutton setImage:seuncheck forState:UIControlStateNormal];
self.title = #"Game";
}
else if(sprakval2==1)
{
spraklabel.text = [NSString stringWithFormat:#"Språk:"];
[lhb setTitle:#"swedish" forState:UIControlStateNormal];
[hlb setTitle:#"swedish" forState:UIControlStateNormal];
[flb setTitle:#"swedish" forState:UIControlStateNormal];
[fhb setTitle:#"swedish" forState:UIControlStateNormal];
[blandatb setTitle:#"swedish" forState:UIControlStateNormal];
self.title = #"Spel";
UIImage *secheck = [UIImage imageNamed:#"Swedenchecked.png"];
[sebutton setImage:secheck forState:UIControlStateNormal];
UIImage *enuncheck = [UIImage imageNamed:#"United_Kingdom.png"];
[enbutton setImage:enuncheck forState:UIControlStateNormal];
}
}
viewDidLoad
- (void)viewDidLoad{
[super viewDidLoad];
[self adjustControlsForLanguage];
}
Button Event Handlers
-(IBAction) sprakEN {
sprakval=0;
NSUserDefaults *sprakvalet = [NSUserDefaults standardUserDefaults];
[sprakvalet setInteger:sprakval forKey:#"Sprak "];
[sprakvalet synchronize];
[self adjustControlsForLanguage];
}
-(IBAction) sprakSE {
sprakval=1;
NSUserDefaults *sprakvalet = [NSUserDefaults standardUserDefaults];
[sprakvalet setInteger:sprakval forKey:#"Sprak "];
[sprakvalet synchronize];
[self adjustControlsForLanguage];
}
EDIT : Since you are using tabBar based app, it's better to use the viewWillAppear to reload the language specific controls
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self adjustControlsForLanguage];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
I have three text fields: first name, last name, and age, also a photo. What can I do so that the information saves automatically, so that i dont have to click a button?
This is my ViewController.h:
#import <UIKit/UIKit.h>
#interface ContactViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
IBOutlet UIImageView *contactImageView;
IBOutlet UITextField *firstNameTextField;
IBOutlet UITextField *lastNameTextField;
IBOutlet UITextField *ageTextField;
}
- (IBAction)save:(id)sender;
- (IBAction)chooseImage:(id)sender;
#end
This is my ViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *frontName = [defaults objectForKey:#"firstname"];
NSString *lastName = [defaults objectForKey:#"lastname"];
int age = [defaults integerForKey:#"age"];
NSString *ageString = [NSString stringWithFormat:#"%i",age];
NSData *imageData = [defaults dataForKey:#"image"];
UIImage *contactImage = [UIImage imageWithData:imageData];
firstNameTextField.text = frontName;
lastNameTextField.text = lastName;
ageTextField.text = ageString;
contactImageView.image = contactImage;
}
- (void)viewDidUnload {
[contactImageView release];
contactImageView = nil;
[firstNameTextField release];
firstNameTextField = nil;
[lastNameTextField release];
lastNameTextField = nil;
[ageTextField release];
ageTextField = nil;
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)save:(id)sender {
[firstNameTextField resignFirstResponder];
[lastNameTextField resignFirstResponder];
[ageTextField resignFirstResponder];
// Create strings and integer to store the text info
NSString *frontName = [firstNameTextField text];
NSString *lastName = [lastNameTextField text];
int age = [[ageTextField text] integerValue];
UIImage *contactImage = contactImageView.image;
NSData *imageData = UIImageJPEGRepresentation(contactImage, 100);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:frontName forKey:#"firstname"];
[defaults setObject:lastName forKey:#"lastname"];
[defaults setInteger:age forKey:#"age"];
[defaults setObject:imageData forKey:#"image"];
[defaults synchronize];
NSLog(#"Data saved");
}
- (IBAction)chooseImage:(id)sender {
UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
contactImageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
you will have to work with the <UITextFieldDelegate> protocol
Reference: UITextFieldDelegate Protocol
you will have to set
textField.delegate = yourViewController
and can then work with the protocol functions, that handle input and character changing of your textview.
for example you cound use
- (BOOL)textFieldShouldReturn:(UITextField *)textField
to save the textfield content when the user presses the return button =)
EDIT: probably this method is better suited for your needs - i was a bit tired yesterday when writing the post =)
- (void)textFieldDidEndEditing:(UITextField *)textField {
//save your textfied.text string here :)
}
You need to set the delegate of the UITextfield to the view controller in your viewDidLoad method like
firstNameTextField.delegate = self;
lastNameTextField.delegate = self;
ageTextField.delegate = self;
Your view controller needs to implement the UITextFieldDelegate Protocol method:
- (void)textFieldDidEndEditing:(UITextField *)textField {
//Do save Operations here
}
This will save only after the text is done editing. If you want to save as the user is typing, use
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *stringToSave=[textField.text stringByReplacingCharactersInRange:range withString:string];
//Identify text field by comparing textField with you text fields and do save operations
return YES;
}