ios:在文本视图中编辑时,键盘返回键不工作
我是ios开发的新手 这是我的字符串变量->“tempDescription”我想在键盘返回键上的字符串变量中存储编辑的文本 这是我的文本视图->“txteditdescription” 但通过以上方法我的模拟器键盘并没有隐藏。 那我该怎么办?ios:在文本视图中编辑时,键盘返回键不工作,ios,swift,keyboard,uitextview,Ios,Swift,Keyboard,Uitextview,我是ios开发的新手 这是我的字符串变量->“tempDescription”我想在键盘返回键上的字符串变量中存储编辑的文本 这是我的文本视图->“txteditdescription” 但通过以上方法我的模拟器键盘并没有隐藏。 那我该怎么办? 谢谢将文本字段拖动到它所连接的viewcontroller,创建一个名为“退出时结束”的操作事件,并随意调用它 然后在函数内部调用 func textView(_ textView: UITextView, shouldChangeTextIn ran
谢谢将文本字段拖动到它所连接的viewcontroller,创建一个名为“退出时结束”的操作事件,并随意调用它 然后在函数内部调用
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if text == "\n" {
tempDescription = txteditdescription.text
txteditdescription.resignFirstResponder()
return false
}
return true
}
像这样
self.resignFirstResponder()
您应该像这样分配代理
@IBAction func dismiss(_ sender: Any) {
self.resignFirstResponder()
}
然后实现委托方法shouldChangeTextInRange
txteditdescription.delegate = self
请访问此链接:在@hardik下面发布我的答案
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
if (text == "\n") {
textView.resignFirstResponder()
return false
}
return true
}