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?
I see you put it in your code, but for future visitors, add this to your code:
following is answer from Mike Gledhill and Warren Crowther updated with xcode 5 screenshot.
(to set UITextField delegate, press and hold ctrl + drag from the UITextField to the "File's Owner" yellow button, shown in image below. if UITextField delegate not set, textFieldShouldReturn method never gets called).
I think you are using xib. If so You also need to set delegate over there. Do Right Click on your UITextfiled in xib and you will have delegate option drag it to your file owner.
I had the delegate set and everything. But I was using a UITextView instead of UITextfield...
Perhaps this will help someone trying to figure why delegate methods are not fired.