Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何实现UITextFieldDelegate_Swift_Xcode_Swift3_Xcode8 - Fatal编程技术网

Swift 如何实现UITextFieldDelegate

Swift 如何实现UITextFieldDelegate,swift,xcode,swift3,xcode8,Swift,Xcode,Swift3,Xcode8,我还在学习swift,我对如何实现UITextFieldDelagate很好奇。我还很好奇,当键盘(FirstResponder)看到我已完成编辑时,我应该如何隐藏它。您的ViewController应该是UITextFieldDelegate。然后将当前ViewController设置为文本字段的委托,在本例中为viewDidLoad() 执行textFieldShouldReturn,以便textField将返回任务(textFieldShouldReturn)委托给ViewControll

我还在学习swift,我对如何实现UITextFieldDelagate很好奇。我还很好奇,当键盘(FirstResponder)看到我已完成编辑时,我应该如何隐藏它。

您的ViewController应该是
UITextFieldDelegate
。然后将当前ViewController设置为文本字段的委托,在本例中为
viewDidLoad()

执行
textFieldShouldReturn
,以便textField将返回任务(textFieldShouldReturn)委托给ViewController。在这个方法调用
resignFirstResponder
,这样键盘就会消失。例如:

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var someTextField: UITextField!

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        someTextField.delegate = self

    }
}

谢谢你@Hapeki