How to configure a delegate for a text field in the interface builder to "file owner"?

I am trying to implement:

- (BOOL) textFieldShouldReturn:(UITextField *)textField 

method. For some reason this is not called. I set a text box for the first responder in the code. I understand that I also need to set a delegate for the text field in the interface builder for the "file owner". How to do it? Thanks!

+6
source share
2 answers

You can right-click and drag from the text box on the canvas of the interface designer to the File Owner icon in the list of objects on the left.

Or you can select a text field, open the output inspector, drag it from the small circle next to the delegate to the File Owner icon in the list of objects.

Or you can right-click and drag from the text box icon in the list of objects to the same File Owner icon in this list.

Or you can set the delegate to code.

+5
source

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

Alternatively, you can do this in the storyboard.

enter image description here

+7
source

Source: https://habr.com/ru/post/980826/


All Articles