8

I am trying to implement the :

- (BOOL) textFieldShouldReturn:(UITextField *)textField

method. For some reason it is not being called. I have set the text field to first responder in the code. I understand I also need to set the delegate for the text field in interface builder to 'files owner'. How do that? Thank you!

Kex
  • 8,023
  • 9
  • 56
  • 129

2 Answers2

17

If you have declared your UITextField as an IBOutlet property, you can just add the following line in your viewDidLoad: self.myTextField.delegate = self

Alternatively, you can do it in Storyboards.

enter image description here

nburk
  • 22,409
  • 18
  • 87
  • 132
6

You can right click drag from the text field on the interface builder canvas to the File's Owner icon in the object list on the left.

Or you can select the text field, open the outlet inspector, drag from the little circle next to delegate over to the File's Owner icon in the object list.

Or you can right click drag from the text field icon in the object list to the same File's Owner icon in that list.

Or you can set the delegate in code.

Andrew Monshizadeh
  • 1,784
  • 11
  • 16