Search code examples
iphoneuikeyboardiphone-softkeyboard

Resign keyboard on 'Done' button of keyboard


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....


Solution

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