iPhone:使用XIB通过完成按钮操作重新启动键盘

时间:2011-01-20 17:45:00

标签: iphone uikeyboard

您正在使用UITextview

如何调整键盘,键盘“完成按钮”后单击动作,哪个XIB

谢谢

4 个答案:

答案 0 :(得分: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的键盘,如果有任何疑虑通知我

谢谢

答案 1 :(得分:9)

创建IBAction并在IB中将其与UITextfield的{​​{1}}事件联系起来。然后拨打DidEndOnExit以使键盘消失。

或者,尝试在IBAction中使用[textViewName resignFirstResponder]

答案 2 :(得分:4)

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

在这些示例中,myTextViewUITextView,它在标头中定义并在Interface Builder中连接。

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

将其指定给外部按钮:

请务必在标题中定义IBAction,然后在界面生成器中,将按钮连接到touchUpInside:

的此操作

·H

-(IBAction)dismissKeyboard:(id)sender;

的.m

-(IBAction)dismissKeyboard:(id)sender {

    [myTextView resignFirstResponder];

}

答案 3 :(得分:0)

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