开发者

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 fo开发者_C百科r "Done" method or so? i am not getting method for "Done" from apple documentation. plz help me ....thanks in advance....


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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜