简体   繁体   中英

How to move to next textField when QuickType suggestion is chosen?

I have three text fields on my screen; the first two are first and last names. I have enabled QuickType so the names can be chosen quickly. When the first name is selected by the QuickType button, I wish the last name text field to become the first responder, and similarly for the third textField to become the first responder when the last name is tapped in the QuickType bar.

Currently, the user has to tap the QuickType bar and then press Return or tap in the next field.

I wonder if there is a way to register when the QuickType bar is pressed as opposed to the main body of the keyboard, or alternatively if there is a way to register when more than one character is entered at the same time? Or if there is some other way of enabling this behavior?

I have seen it in action in other apps, but can't find a solution despite looking.

Thoughts would be very helpful, please!

If string.count > 1, then the user isn't manually typing. This is just an example, you'll need to check the textField to see if it's for first name, last name, etc. and act accordingly.

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  if string.count > 1 {
    textField.text = string
    nextTextField.becomeFirstResponder()
  }
  return true
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM