Swift 致命错误:在展开可选值(lldb)时意外发现nil
嘿,所以每次我试着运行代码关闭键盘时,我都会收到这个消息,其他部分都会工作,直到我添加这些代码行。 如果有人能帮忙,那太好了,谢谢 代码从这里开始Swift 致命错误:在展开可选值(lldb)时意外发现nil,swift,keyboard,Swift,Keyboard,嘿,所以每次我试着运行代码关闭键盘时,我都会收到这个消息,其他部分都会工作,直到我添加这些代码行。 如果有人能帮忙,那太好了,谢谢 代码从这里开始 override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { self.view.endEditing(true) //closes keyboard } func textFieldS
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
{
self.view.endEditing(true)
//closes keyboard
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}
试试这个检查你的文本字段输出。这是我最初的输出,但现在它说后缀“?”的操作数应该有可选类型;类型为“UITextField”。现在,它无法构建并修复它,它希望删除问号。实际上,我只是重新编写了应用程序的所有代码,错误消失了,即使我有相同的代码。你可能知道为什么即使我修复了它,错误仍然存在吗?谢谢你的时间和努力!
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
{
self.view.endEditing(true)
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
if textField.text != nil
{
textField.resignFirstResponder()
}
you can also try
if textField != nil
{
textField.resignFirstResponder()
}
return true
}
}