一,UITextView取消第一响应
UITextView *editTextView = [[UITextView alloc] init];
self.editTextView = editTextView;
editTextView.returnKeyType = UIReturnKeyDone;
[imageView addSubview:editTextView];
editTextView.delegate = self;
#pragma mark - UITextView Delegate Methods
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if ([text isEqualToString:@" "]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
二,UITextField取消第一响应
field.returnKeyType = UIReturnKeyDone;
[field addTarget:self action:@selector(onKeyBoardDown:) forControlEvents:UIControlEventEditingDidEndOnExit];// 取消第一响应
-(void)onKeyBoardDown:(id)sender{
[sender resignFirstResponder];
}
或者
UIBarButtonItem *done = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(leaveEditMode)] autorelease];
self.navigationItem.rightBarButtonItem = done;
}
- (void)textViewDidEndEditing:(UITextView *)textView {
self.navigationItem.rightBarButtonItem = nil;
}
- (void)leaveEditMode {
[self.textView resignFirstResponder];
}
或者
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}