(iOS8, Xcode6, Swift) Using Swift, how do I capture a tap on the "Return" button?
The doc at the following link specifies using the textFieldShouldReturn
method:
// Swift
@optional func textFieldShouldReturn(_ textField: UITextField!) -> Bool
Where I'm hung up is in the "_ textField" part. I've created the text field using Storyboard. How do I capture notifications for this specific text field? Do I need to create a new class and set it as a delegate for this text field? Do I assign the text filed a name, and then somehow hook into it?
https://developer.apple.com/documentation/uikit/uitextfielddelegate/1619603-textfieldshouldreturn
Implement this function
And for delegate you can set using the Utilities pane / Connections Inspector / delegate and then drag to ViewController (yellow button in the storyboard)
Then you do not need to set the delegate programmatically for every text field
You need to set an object as the text field's delegate. Usually that would be the view controller that the text field exists in. You don't need to inherit from any other class, or, strictly speaking, implement a delegate (but you could implement UITextFieldDelegate to make things a little clearer.)
In Swift 4.2 and Xcode 10.1