ios – 当点击uitextfield的清除按钮键盘正在消失而不是文字

前端之家收集整理的这篇文章主要介绍了ios – 当点击uitextfield的清除按钮键盘正在消失而不是文字前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在iPhone中,我看到它有UITextField.当我点击UITextField的键盘的清除按钮正在消失,而不是UITextField.In ipad samething中的文本正常工作.请建议我,该怎么办?
提前致谢!!

解决方法

只要清除字段,resignFirstResponder(如果你想隐藏键盘)并返回NO / false
  1. Note: set Attributes inspector property of UITextField

Clear Button -> Appears while editing

  1. so it will display 'X' button while editing in textfield.

// Objective-C

  1. -(BOOL)textFieldShouldClear:(UITextField *)textField
  2. {
  3. textField.text = @"";
  4. [textField resignFirstResponder];
  5. return NO;
  6. }

// Swift

  1. func textFieldShouldClear(textField: UITextField) -> Bool {
  2. textField.text = ""
  3. textField.resignFirstResponder()
  4. return false
  5. }

猜你在找的iOS相关文章