I think you're using the wrong method ... textFieldDoneEditing fires when a control loses focus, not when the "return" key gets tapped.
Try implementing optional func textFieldShouldReturn(_ *textField*: UITextField <https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/index.html#//apple_ref/swift/cl/c:objc%28cs%29UITextField>) -> Bool <https://developer.apple.com/library/ios/documentation/Swift/Reference/Swift_Bool_Structure/index.html#//apple_ref/swift/struct/s:Sb> https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextFieldDelegate_Protocol/#//apple_ref/occ/intfm/UITextFieldDelegate/textFieldShouldReturn : Thanks, -Luther On Mon, Jul 4, 2016 at 2:17 PM, William Squires <wsqui...@satx.rr.com> wrote: > When making any iOS application project (Xcode 7.something, on 10.11.5, > base SDK = iOS 9) that uses a UITextField control, I can't get the "return" > button to work. > > I've tried attaching an IBAction by Ctrl-dragging from the control to the > .swift file for the view controller, naming the action, and selecting > "Action" (instead of "outlet"), and it creates the action method as below: > > @IBAction func textFieldDoneEditing(sender: UITextField) { > print("textFileDoneEditing:") > sender.resignFirstResponder() > } > > I've verified that the connection is valid. Not only does the > dot-in-a-circle show up to the left of the func, I can see that it's > connected in the connections inspector pane. When I run (simulator or > actual device) no output is logged to the console when the return key on > the on-screen keyboard is tapped (clicked, in the case of the simulator.) > > I also tried setting my view controller to implement UITextFieldDelegate > > class ViewController : UIViewController , UITextFieldDelegate > { > ... > func textFieldDidEndEditing(textField: UITextField) { > print("textFieldDidEndEditing:") > self.resignFirstResponder() > } > > then went back to IB and the connections inspector pane. I then selected > both of my UITextFields and made sure the delegate was connected to the > proxy for the view controller (at the top of the "view controller" IB > representation, to the left of the "File's Owner" and "Exit" proxies). > > In neither case, does this work on either the simulator or device. Only > once I tap on the other UITextField (set to have a numeric keypad) do both > methods print to the console, by which time it's too late; the other text > field already has the focus (first responder status.) > > I don't know if this is an iOS bug, or an ID10T error (stupidity on my > part). Please help!! > > BTW, I also have two outlets to the UITextFields in question, one named > "nameField" and one named "numberField". The first has the "default" > keyboard, and the 2nd has the "numpad" keyboard; it's the first one that > has the non-responsive "return" button (since a numpad keyboard doesn't > have a "return" button - a sad oversight, IMHO) > > > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/lutherbaker%40gmail.com > > This email sent to lutherba...@gmail.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com