swift 3.0 - UITextFieldDelegate协议扩展无法正常工作

时间:2016-10-16 13:00:12

标签: ios swift3 uitextfielddelegate

我在UITextFieldDelegate中尝试实施ViewController协议。我从apple tutorial开始。我实现了相同的,如它在教程,但它不起作用。 (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
    }

}

1 个答案:

答案 0 :(得分:0)

您可以尝试删除textField委托中的第一行。