I have TextView.In TextView i have to set maximum 160 character to TextView including space.If i click return the keyboard should go down.I have coding.It works after enter 160 character only.So if i click retun, immeadiately it should go down and it should not be after 160 character including space.Even if i click return after entering "how are you?" in the text view,the keyboard should hide.
My Coding is
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
//First type for space
/*
return txtviewAsk.text.length + (text.length - range.length) <= 160;
[txtviewAsk resignFirstResponder];
*/
//Second type with correct method
NSUInteger newLength = (textView.text.length - range.length) + text.length;
if(newLength <= MAX_LENGTH)
{
//[txtview resignFirstResponder];
return YES;
}
else
{
NSUInteger emptySpace = MAX_LENGTH - (textView.text.length - range.length);
textView.text = [[[textView.text substringToIndex:range.location]
stringByAppendingString:[text substringToIndex:emptySpace]]
stringByAppendingString:[textView.text substringFromIndex:(range.location + range.length)]];
[txtviewAsk resignFirstResponder];
return NO;
}
}