Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textFieldShouldReturn not being called in iOS

We're trying to figure out how to get the keyboard to hide, but we're having problems getting the textFieldShouldReturn to fire. Why?

This is what has been done:

*.h

@interface MultiSalesViewController : UIViewController <UITextFieldDelegate> 

*.c

txtCardNumber.delegate = self;  - (BOOL)textFieldShouldReturn:(UITextField *)textField {     [textField setUserInteractionEnabled:YES];     [textField resignFirstResponder];     return YES; } 

Also, the textField has its delegate set to Files Owner in Interface Builder. One odd thing, is that the viewController's - (void)textFieldDidEndEditing:(UITextField *)textField is working.

How to get the hiding of the keyboard working?

like image 282
iPhone Developer Avatar asked Jan 07 '11 14:01

iPhone Developer


People also ask

What does textfieldshouldreturn do?

Asks the delegate whether to process the pressing of the Return button for the text field.

What is resignFirstResponder Swift?

If you want that text control to stop waiting for input – which in turn dismisses the keyboard – you should call its resignFirstResponder() method, which passes the first responder baton to the next waiting component.

What is Textfield delegate in Swift?

A set of optional methods to manage the editing and validation of text in a text field object.


2 Answers

I had the exact same issue and it was because I forgot to set the delegate for the text field in interface builder to 'files owner'.

like image 121
Warren Crowther Avatar answered Sep 17 '22 15:09

Warren Crowther


I had the same problem and, as Warren Crowther suggested, I managed to solve it by holding down CTRL and dragging from the TextBox to the "File's Owner" label.

(Gosh, I miss Visual Studio sometimes...!!)

enter image description here

(Apologies for repeating what's already been said, but I thought a screenshot might be useful !)

like image 23
Mike Gledhill Avatar answered Sep 18 '22 15:09

Mike Gledhill