0

I try implement UITextFieldDelegate protocol in ViewController. I have started with apple tutorial. I implemented the same such as it is on tutorial but it doesn't work. (XCODE 8)

class ViewController: UIViewController, UITextFieldDelegate {

    // MARK: Properties

    @IBOutlet weak var recipeNameField: UITextField!
    @IBOutlet weak var recipeNameLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        recipeNameField.delegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: Actions

    @IBAction func onSetDefaultRecipeClick(_ sender: UIButton) {
        recipeNameField.text = "Deafult recipe name"
    }

    // MARK: UITextFieldDelegate
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()

        print("return")
        return true
    }

}
Michael
  • 780
  • 1
  • 10
  • 34

1 Answers1

0

You can try to delete the first line in textField delegate.

Guan
  • 138
  • 7
  • 1
    `func textFieldShouldReturn(_ textField: UITextField) -> Bool { print("return") return true }` – Guan Oct 16 '16 at 13:56