0

In my app i'm using a UITextField collect a string value. Whenever i finish editing the field, textFieldDidEndEditing gets fired, but later textFieldShouldReturn never. What can be it's reason?

I provide some code:

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

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if(textField == self.urlPatternTextField) {

      /*do some stuff*/
    }
}

- (IBAction)dismissKeyboard:(id)sender {

    NSMutableArray* possibleReponders = [[NSMutableArray alloc]initWithObjects:
                                         self.urlPatternTextField, nil];

    for (UITextView* tv in possibleReponders) {
        if([tv isFirstResponder]) {

            [tv resignFirstResponder];
            return;
        }
    }
}

Note:

In textFieldDidEndEditing the if condition is true.

Thanks for the help in advance.

Sincerely,

Zoli

user7388
  • 1,741
  • 2
  • 19
  • 25
Zoltan Varadi
  • 2,468
  • 2
  • 34
  • 51

1 Answers1

1

textFieldShouldReturn:

Asks the delegate if the text field should process the pressing of the return button.

- (BOOL)textFieldShouldReturn:(UITextField *)textField 

Parameters

textField The text field whose return button was pressed.

Return Value YES if the text field should implement its default behavior for the return button; otherwise, NO.

Discussion The text field calls this method whenever the user taps the return button. You can use this method to implement any custom behavior when the button is tapped.

The method invokes when return button is pressed.Try it so

Community
  • 1
  • 1
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
  • i changed the return value to NO, now when i press the return button textFieldShouldReturn fires, but it still doesn't dismiss the keyboard – Zoltan Varadi Jun 17 '13 at 12:06
  • Return Value YES if the text field should implement its default behavior for the return button; – Lithu T.V Jun 17 '13 at 12:07
  • call `[textField resignFirstResponder];` on both the methods `textFieldDidEndEditing` and `textFieldShouldReturn` – Lithu T.V Jun 17 '13 at 12:15
  • still nothing. Strange. I have implemented this like a 100 times before. However in this case the UIViewController is presented modally on the top of an other UIViewController. Could this mess things up? – Zoltan Varadi Jun 17 '13 at 12:18
  • @ZoltanVaradi- Strangly it happened with me. today i added manually delegate..have u done that – Vivek Sehrawat Jun 17 '13 at 12:27
  • Turns out modal views do mess up the keyboard handler: http://stackoverflow.com/questions/3372333/ipad-keyboard-will-not-dismiss-if-modal-view-controller-presentation-style-is-ui – Zoltan Varadi Jun 17 '13 at 13:04