嗨,我正在研究 UITextview
如何辞职键盘,键盘“完成按钮”后点击动作,其中XIB
谢谢
嗨,如果您想回答,请使用键盘上的默认“完成”按钮重新注册 UITextview 的键盘,那么这就是答案
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text {
// Any new character added is passed in as the "text" parameter
if([text isEqualToString:@"\n"]) {
// Be sure to test for equality using the "isEqualToString" message
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added
return NO;
}
// For any other character return TRUE so that the text gets added to the view
return YES;
}
我按照这个辞掉了 UITextview 的键盘,如果有任何问题请告诉我
谢谢你
创建一个IBAction
并在 IB 中将其连接到UITextfield
'DidEndOnExit
事件。然后调用[textViewName resignFirstResponder]
使键盘消失。
或者,尝试[self.view endEditing:YES]
在 IBAction 中使用。
要将操作分配给Done
键盘的按钮:
在这些示例中,myTextView
是UITextView
在标头中定义并在 Interface Builder 中连接的。
-(BOOL)textViewShouldReturn:(UITextView*)textView {
if (textView == myTextView) {
[textView resignFirstResponder];
}
return YES;
}
要将其分配给外部按钮:
请务必IBAction
在标题中定义一个,然后在 Interface Builder 中,将按钮连接到此操作以touchUpInside:
-(IBAction)dismissKeyboard:(id)sender;
-(IBAction)dismissKeyboard:(id)sender {
[myTextView resignFirstResponder];
}
调用resignFirstResponder
具有焦点的文本视图以关闭键盘。