• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Supreme aggravation with UITextField controls and the #@Q% return button
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Supreme aggravation with UITextField controls and the #@Q% return button


  • Subject: Re: Supreme aggravation with UITextField controls and the #@Q% return button
  • From: Luther Baker <email@hidden>
  • Date: Mon, 04 Jul 2016 22:31:50 -0500

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(cs)UITextField>)
-> 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 <email@hidden>
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 (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


References: 
 >Supreme aggravation with UITextField controls and the #@Q% return button (From: William Squires <email@hidden>)

  • Prev by Date: Supreme aggravation with UITextField controls and the #@Q% return button
  • Next by Date: iOS Status Bar and Modal Presentation
  • Previous by thread: Supreme aggravation with UITextField controls and the #@Q% return button
  • Next by thread: iOS Status Bar and Modal Presentation
  • Index(es):
    • Date
    • Thread