我无法让UITextView键盘消失

时间:2013-03-05 02:12:37

标签: xcode

嗨,这是我的代码,我试图让UI文本视图键盘消失。我有2个文本字段,第二个是文本视图。我试着拖动动作,但它不会让我。请帮忙!!!!!

- (IBAction)dismiss1:(id)sender{

[sender resignFirstResponder];
}

- (IBAction)dismiss2:(id)sender2{

[field2 resignFirstResponder];
}

1 个答案:

答案 0 :(得分:0)

UITextView没有事件操作。

Import <UITableViewDelegate, UITableViewDataSource> in header file and use below code to disapear keyboard when click on return button.

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{

    if ([text isEqualToString:@"\n"]) {

        [self.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;
}