当点击uitextfield的清除button键盘消失而不是文本
在iPhone中,我有它的UITextField
查看。当我点击UITextField
的键盘上的清除button正在消失,而不是UITextField
的文本。在iPad中,一切正常。 请build议我,该怎么办? 提前致谢!!
只要清除该字段,resignFirstResponder(如果你想隐藏键盘)并返回NO / false
Note: set Attributes inspector property of UITextField
清除button – >编辑时出现
so it will display 'X' button while editing in textfield.
// Objective-C
-(BOOL)textFieldShouldClear:(UITextField *)textField { textField.text = @""; [textField resignFirstResponder]; return NO; }
// Swift
func textFieldShouldClear(textField: UITextField) -> Bool { textField.text = "" textField.resignFirstResponder() return false }
在附上uitextifield的委托后,尝试执行此代码
-(BOOL)textFieldShouldClear:(UITextField *)textField { return true; }
首先,检查所有与你的UITextField
相关的代码块(特别是代码yourTextField.hidden = YES;
)
放置中断点并分析您实施的每个UITextField
委托。
( textFieldDidEndEditing
, textFieldShouldEndEditing
, textFieldShouldReturn.etc
。 )
要么
实现textFieldShouldClear
委托,并在这里写代码可见并清除你的UITextField
要做到这一点,你必须如下设置clearButtonMode
,
yourTextField.clearButtonMode = UITextFieldViewModeWhileEditing; yourTextField.delegate = self; //For active keyboard again [yourTextField becomeFirstResponder];
然后执行textFieldShouldClear
委托
YourClass.h
@interface className : UIViewController <UITextFieldDelegate>
YourClass.m
-(BOOL)textFieldShouldClear:(UITextField *)textField { yourTextField.hidden = NO; yourTextField.text = @""; return YES; }
只要确定我给了这两个
editingTextField.delegate = self; editingTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
TextFieldShouldClear仅在需要进行一些自定义时才需要:-)
你用这种方法做了些什么?
也许你是在这个委托方法调用resignFirstResponder,这就是为什么键盘被解雇。
请通过委托方法,并检查你在做什么。
如果你有这个问题,也会发生
yourTextField.clearButtonMode = UITextFieldViewModeNever;
选中此行并将其删除或更改查看模式..
- 如何获得键盘大小调整UITextView和如何使用UIKeyboardFrameEndUserInfoKey与日本键盘?
- iOS键盘显示事件处理
- 在iOS8 WebView中删除“自定义键盘”的“下一个/上一个”button(inputAccessoryView)
- 如何为iOS创build新的自定义情感键盘(有点像表情符号)
- 如何防止键盘在iOS应用程序使用phonegap推高webview
- 使用UIView同步animation键盘,同时在iOS7中向后滑动
- 如何停止在UITextview点击事件keyBoard出现?
- 解除键盘后如何保持UITextField的游标处于焦点状态?
- 有什么好的教程在iOS自定义键盘实现吗?