2

I have two uitextview in storyboard. What I need is when the user type something in one textview should show the exact same data in another textview, also when the text is below the textview area it should automatically scroll up showing the last line. This is my code in uitextview delegate

<code>
-(void)textViewDidChange:(UITextView *)textView
{
    self.textview2.text = textview.text;
    NSRange selection = self.textview2.selectedRange;

        [self.textview2 scrollRangeToVisible:NSMakeRange([self.textview2.text length], 0)];];

}
</code>

This code works but the problem is everytime it scrolls from top to bottom which irritates user. Any solution will be appreciated?

2 Answers 2

1

Try this dude

-(void)textViewDidChange:(UITextView *)textView
{

    self.textview2.text = textview.text;

    [self.textview2 scrollRectToVisible:CGRectMake(0, self.textview2.contentSize.height, self.textview2.contentSize.width, CGFLOAT_MAX)
                               animated:NO];
}
Sign up to request clarification or add additional context in comments.

Comments

0

Both textView must have the viewController as delegate:

     self.textView1.delegate = self;
     self.textview2.delegate = self;

Then implement this methods in this way:

 -(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if ([scrollView isEqual:self.textview2])
{
     [self.textview2 scrollRangeToVisible:NSMakeRange([self.textview2.text length], 0)];

}
}

-(void)textViewDidChange:(UITextView *)textView
  {

 if ([textView isEqual:self.textView1])
 {


self.textview2.text = textView.text;

[self.textview2 scrollRangeToVisible:NSMakeRange([self.textview2.text length], 0)];
}

}

The problem is the way textView work, when you make this: self.textview2.text = textView.text; the text in the textView is first point to nil, (no text, contentOffSet point to 0.0), then the new text is pointing. The content change between zero and a big content (in fact bigger and bigger). the textContainer and textStorage of the text view are in charge of this work...

19 Comments

thank you for the help, but this is not my requirement. I need another textview to be scroll bottom when the user type and press return key in the first textview
@user1495387 Try this answer, please.
this is some how the same way i did, and i told you it scroll from top to bottom everytime i enter return key
What do you want to happen, when you press the return key, and how do you do the textView end editing ?
@user1495387 another question, both textView have the same dimensions and fonts ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.