1

I have a UITextField and UITextView in a view.

The scenario is like this:

  • textFieldShouldReturn: method of the UITextField makes UITextView the firstResponder

And now the problem is , every time my textView becomes the first responder the contentSize of the UITextView increases(ie,every time the cursor moves to a new line)..

Is there any way that the textView's contentsize remains the same???

Thanxx in advance..

Midas
  • 930
  • 2
  • 8
  • 20
  • for this is happens only in ios 7 – codercat Feb 07 '14 at 07:25
  • http://stackoverflow.com/questions/19028743/ios7-uitextview-contentsize-height-alternative – codercat Feb 07 '14 at 07:36
  • I have simply add a textfield and a textview via xib. And in textFieldShouldReturn I set textview firstResponder.. -(BOOL)textFieldShouldReturn:(UITextField *)textField { [myTextView becomeFirstResponder]; } – Midas Feb 07 '14 at 08:27
  • I encountered this problem in my main project.. So I created this sample one just to check.. – Midas Feb 07 '14 at 08:29
  • Please try this, [myTextView sizeToFit]; [myTextView layoutIfNeeded]; – cjd Feb 07 '14 at 09:35

2 Answers2

1

use this code.This will solve your problem.

-(BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        if([textField isEqual:myTextField])
        {
            [myTextField resignFirstResponder];
            [myTextView becomeFirstResponder];
            return NO;
        }
        return YES;
    }
0

before set contentSize use sizeToFit

or refer below links it will help you

iOS7 UITextView contentsize.height alternative

Community
  • 1
  • 1
codercat
  • 22,873
  • 9
  • 61
  • 85