Heena
Heena

Reputation: 2358

Which UITextField delegate method will be called without resing keyboard?

I am in situation where user enters data into UITextField in without resign of keyboard he presses Next button go to next page.

That textfield is in custom cell with UITextView. Now I want to capture everything in every textfield & UITextView of that UITableView when user enters into it because at time of Next button click I need to save the data.

Till Now I have implemented below methods but none of these getting called when user enters data into TextField and directly press Next button without returning keyboard

- (void)textFieldDidEndEditing:(UITextField *)textField
{

    NSString *strTitle = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    textField.text = strTitle;


}


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{   

    return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

What could be the best wat to save from that TextFields before Next?

Upvotes: 0

Views: 2320

Answers (4)

hchouhan02
hchouhan02

Reputation: 946

If you are using a custom cell then use this

[[(CustomCellName *)[tableViewName cellForRowAtIndexPath:indexPathOfRowNo] textFieldName] text];

Upvotes: 0

Manish Ahuja
Manish Ahuja

Reputation: 4517

If you just want to know the content of your textfield and textview when user taps the next button then you don't need to know which delegate method will be called, you can simply get those values in the IBAction method for next button

-(IBAction)nextButtonTapped {
    textFieldData = myTextField.text;
    textViewData =  myTextView.text;

   //code to push the next view goes here
}

Hope this helps!

Upvotes: 0

Vignesh
Vignesh

Reputation: 10251

textFieldDidEndEditing in not always called when you lose the focus. see the post https://stackoverflow.com/a/1229914/641062. It explains a bit about more about the endEditing method's behaviour.

So must save your data in this method. This will called for every character you type.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{   

    return YES;
}

Upvotes: 0

Conrad Shultz
Conrad Shultz

Reputation: 8808

At least one of those definitely should be called.

Could be something really simple, though: have you double-checked that the class implementing those methods has actually been assigned as the delegate of the UITextField in question?

Upvotes: 0

Related Questions