textFieldShouldReturn not being called in iOS

不问归期 提交于 2019-12-02 23:27:04

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'.

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...!!)

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

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.

I see you put it in your code, but for future visitors, add this to your code:

yourTextField.delegate = self;

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.

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 had everything wired up just right and - (BOOL)textFieldShouldReturn:(UITextField *)textField was still not being called!

As a work around I configured a method to fire on 'EditingDidEnd':

be sure that your MultiSalesViewController implements the UITextFieldDelegate protocol:

@interface MultiSalesViewController : UIViewController <UITextFieldDelegate>

try adding [self becomeFirstResponder]; after [textField resignFirstResponder];


edit: just another thought.. does your UITextField have a value set for returnKeyType?

txtCardNumber.returnKeyType = UIReturnKeyDone;

i'm not sure if this has to be set for the function to work

Go to Connection Inspector and connect delegate to view controller .thats it .

Checklist to get it to work:

  • Did you set your controller as delegate to UITextField Instance?

  • Make sure controller is not being deallocated by either assigning to property (Autorelease) or explicit retaining it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!