(iOS8、Xcode6、斯威夫特)
使用 Swift,如何捕获“返回”按钮上的点击?
以下链接中的文档指定使用textFieldShouldReturn
方法:
// Swift
@optional func textFieldShouldReturn(_ textField: UITextField!) -> Bool
我挂断的地方是“_ textField”部分。我已经使用情节提要创建了文本字段。如何捕获此特定文本字段的通知?我是否需要创建一个新类并将其设置为该文本字段的委托?我是否为文本文件分配一个名称,然后以某种方式连接到它?
https://developer.apple.com/documentation/uikit/uitextfielddelegate/1619603-textfieldshouldreturn https://developer.apple.com/documentation/uikit/uitextfielddelegate/1619603-textfieldshouldreturn
class ViewController: UIViewController,UITextFieldDelegate //set delegate to class
@IBOutlet var txtValue: UITextField //create a textfile variable
override func viewDidLoad() {
super.viewDidLoad()
txtValue.delegate = self //set delegate to textfile
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool { //delegate method
textField.resignFirstResponder()
return true
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)