iPhone:通过 XIB 完成按钮操作来放弃键盘

发布于 2024-10-13 15:27:07 字数 71 浏览 7 评论 0原文

您好,我正在研究 UITextview

如何退出键盘,在键盘“完成按钮”后单击操作,XIB

谢谢

hi i am working on UITextview

how to Resign Keyboard, after keyboard "Done button" click Action, which XIB

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

调妓 2024-10-20 15:27:07

您好,如果您想回答,使用键盘上默认的“完成”按钮退出 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 键盘的答案,如果有任何问题,请告诉我,

谢谢

hi if you want answer for, Resign the keyboard of UITextview with default "Done" button on keyboard, then this is answer for that

- (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;
}

i followed this to resign keyboard of UITextview, if there is any concern inform me

Thank You

姜生凉生 2024-10-20 15:27:07

创建一个 IBAction 并在 IB 中将其连接到 UITextfieldDidEndOnExit 事件。然后调用 [textViewName resignFirstResponder] 让键盘消失。

或者,尝试在 IBAction 中使用 [self.view endEditing:YES]

Create an IBAction and in IB hook it up to the UITextfield's DidEndOnExit event. Then call the [textViewName resignFirstResponder] to make the keyboard go away.

Alternatively, try using [self.view endEditing:YES] in the IBAction.

梦断已成空 2024-10-20 15:27:07

要将操作分配给键盘的 Done 按钮:

在这些示例中,myTextView 是标头中定义的 UITextView并在 Interface Builder 中连接。

-(BOOL)textViewShouldReturn:(UITextView*)textView {
    if (textView == myTextView) {
        [textView resignFirstResponder];
    }
    return YES;
}

要将其分配给外部按钮:

请务必在标头中定义一个 IBAction,然后在 Interface Builder 中将按钮连接到 的此操作touchUpInside:

.h

-(IBAction)dismissKeyboard:(id)sender;

.m

-(IBAction)dismissKeyboard:(id)sender {

    [myTextView resignFirstResponder];

}

To assign the action to the Done button of a keyboard:

In these examples, myTextView is a UITextView that is defined in the header and connected in Interface Builder.

-(BOOL)textViewShouldReturn:(UITextView*)textView {
    if (textView == myTextView) {
        [textView resignFirstResponder];
    }
    return YES;
}

To assign it to an external button:

Be sure to define an IBAction in your header, then in Interface Builder, connect the button to this action for touchUpInside:

.h

-(IBAction)dismissKeyboard:(id)sender;

.m

-(IBAction)dismissKeyboard:(id)sender {

    [myTextView resignFirstResponder];

}
未央 2024-10-20 15:27:07

在具有焦点的文本视图上调用 resignFirstResponder 以关闭键盘。

Call resignFirstResponder on the textview that has focus in order to dismiss the keyboard.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文