Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not type text in textview

I have an editable textview to enter some description . when i click on the textview the keyboard appears. My problem is when i try to enter some text via keyboard it is not coming in the textview. Please help me thanks in advance.

like image 904
Melbourne Avatar asked Dec 11 '25 09:12

Melbourne


2 Answers

You should not return NO in ...

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

otherwise it will not allow you to add text.

Edit: From TextView reference:

textView:shouldChangeTextInRange:replacementText: Asks the delegate whether the specified text should be replaced in the text view.

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

Parameters:

textView: The text view containing the changes.

range: The current selection range. If the length of the range is 0, range reflects the current insertion point. If the user presses the Delete key, the length of the range is 1 and an empty string object replaces that single character.

text: The text to insert.

Return Value: YES if the old text should be replaced by the new text; NO if the replacement operation should be aborted.

like image 127
Nuzhat Zari Avatar answered Dec 12 '25 21:12

Nuzhat Zari


You must return YES in this delegate method, else no text whatsoever will be allowed in fields that you are the delegate of, like so:

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

    if([text isEqualToString:@"\n"]) {
        [m_CtrlTxtViewDescription resignFirstResponder];
        [self setViewMovedUp:NO];
        return NO;
    }    
    return YES;
}

shouldChangeTextInRange..., as the name suggests, is the method that the text view calls when text is added through the keyboard. Delegates are asked whether or not text should be added.

like image 42
CodaFi Avatar answered Dec 12 '25 21:12

CodaFi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!