实现textFiel和textView中的键盘的关闭

实现委托UITextFieldDelegate, UITextViewDelegate里以下方法

#pragma mark 放弃“第一响应者”
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

-(BOOL)textView:(UITextView *) textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if([text isEqualToString:@"\n"]){
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

posted @ 2015-03-31 21:12  静坐观雨  阅读(118)  评论(0编辑  收藏  举报