Resign keyboard on 'Done' button of keyboard

1.7k views Asked by At

I want to resign keyboard on click of 'Done' button on keyboard. How can i do this? I have following code =>

textView.returnKeyType = UIReturnKeyDone;

I have this code for limiting number of characters in textview =>

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

   if(range.length > text.length)
    {
        return YES;
    }

    else if([[textView text] length]  >= MAX_LENGTH_TEXTVIEW && range.length == 0)
    {
        [textView resignFirstResponder];
        return NO;

    }

    return YES;
} 

How can i resign keyboard on clicking "Done" button of keyboard? If i click on Done , it's not resigning instead it is going to next line (i.e \n ). Is there any delegate method for "Done" method or so? i am not getting method for "Done" from apple documentation. plz help me ....thanks in advance....

2

There are 2 answers

2
zakovyrya On BEST ANSWER

Your delegate should implement - (BOOL)textFieldShouldReturn:(UITextField *)textField method

2
Nava Carmon On

May be you can add another piece of code to your function:

if([[textView text] isEqualToString:@"\n"]) {
    [textView resignFirstResponder];
    return NO;
}