在 iPhone 中,我有一个包含 UITextField
的 View 。当我点击 UITextField
的清除按钮时,键盘消失了,而不是清除 UITextField
中的文本。在 iPad 上它工作正常。我该怎么做才能解决这个问题?
最佳答案
只需清除字段,resignFirstResponder
(如果你想隐藏键盘)并返回NO
/false
注意:设置 UITextField
的 Attributes inspector 属性
Clear Button -> Appears while editing
因此在文本字段中编辑时会显示清除按钮。
// objective-C
-(BOOL)textFieldShouldClear:(UITextField *)textField
{
textField.text = @"";
[textField resignFirstResponder];
return NO;
}
// swift
func textFieldShouldClear(textField: UITextField) -> Bool {
textField.text = ""
textField.resignFirstResponder()
return false
}
关于ios - 点击 TextField 清除按钮隐藏键盘而不是清除文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11337961/