5

嗨,我正在研究 UITextview

如何辞职键盘,键盘“完成按钮”后点击动作,其中XIB

谢谢

4

4 回答 4

11

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

谢谢你

于 2011-02-01T09:45:13.750 回答
9

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

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

于 2011-01-20T18:28:38.450 回答
4

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

在这些示例中,myTextViewUITextView在标头中定义并在 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];

}
于 2011-01-20T18:28:03.780 回答
0

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

于 2011-01-20T18:04:46.513 回答