I am using UITextfied
while clicking on textfied keyboard appear but when i pressed the return key, keyboard is not disappearing. I used the following code:
func textFieldShouldReturn(textField: UITextField!) -> Bool // called when 'return' key pressed. return NO to ignore.
{
return true;
}
resignfirstresponder 方法未生效。
您可以使用以下函数使应用程序关闭键盘
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.view.endEditing(true)
return false
}
这是一个完整的示例,可以更好地说明这一点:
//
// ViewController.swift
//
//
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet var myTextField : UITextField
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.myTextField.delegate = self
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.view.endEditing(true)
return false
}
}
代码来源:http://www.snip2code.com/Snippet/85930/swift-delegate-sample
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)