Gopinath
Gopinath

Reputation: 5442

Add two UITextView issue in iPhone?

I have added two textview in iphone by this way. I have two UITextView A and B. I have added the UITextView B on UITextView A by like this,

[A addSubview:B]; 
[self.view addSubview:A];

while am start to type in textview, the text is appearing in both textview fine. When the text reach to the final line of the frame size it starting to scroll automatically in textview B but, textview A not scrolling automatically. It is possible to add UITextView subview of UITextView and access both two textview. Can any one please help me. Thanks in advance.

Upvotes: 0

Views: 390

Answers (2)

Jodocus
Jodocus

Reputation: 151

@basvk already hinted to this direction: Don't place an UITextView as a subview in another UITextView. This will result in undefined behavior. They function better as subviews of the same superview. Create some methods to place text in both textViews at once, but use two outlets.

Upvotes: 0

Maulik
Maulik

Reputation: 19418

You can start with

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

delegate method. In this method you can set the string/text to your B text view like :

- (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
   if (textView.tag == 1001] // Text view A
   {
      [tempString appendString:string]; // The tempString is mutable string
      textViewB.text = temp;
   }

    return TRUE;      
} 

Hope it gives you an idea. (Not Fully tested code.)

Upvotes: 1

Related Questions