Skip to content

Observing UITextField text interferes with becomeFirstResponder() #9

@creister

Description

@creister

Discovered this while trying to select subsequent text field during textFieldShouldReturn.
I think this is an issue in Bond as well, I saw it there first.

import UIKit
import ReactiveUIKit

class ViewController: UIViewController {

  @IBOutlet weak var textField1: UITextField!
  @IBOutlet weak var textField2: UITextField!

  override func viewDidLoad() {
    super.viewDidLoad()

    textField1.delegate = self
    textField2.delegate = self

    // by observing textField2 we can't make it first responder when
    // textField1 should return.
    textField2.rText.observe { text in
      print(text)
    }
  }

}

extension ViewController: UITextFieldDelegate {
  func textFieldShouldReturn(textField: UITextField) -> Bool {
    if textField == textField1 {
      textField2.becomeFirstResponder()
    }
    return true
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions