0

I have a UITableView with a UITextView inside. When I run it on the simulator, the textView disapears. Here are some pictures to illustrate what's going on:

Stroyboard: enter image description here

(The textView is in green.)

enter image description here (textViews constraints)

When I run it on the simulator:

enter image description here (The textView disapears.)

The textView's height will be dynamic. So I tried creating a height constraint with the relation to 'greater than or equal', and the textView's height didn't change.

(Note: when I add a textField, (not a textView), it works fine.)

Question:

Why does the textView disappear when I run it on the simulator, and how can I fix it?

  • What height are you setting the row to? Why not put the text view in a modal and present it on demand? – Wain Mar 13 '15 at 20:49
  • `uitableviewautomaticdimension` –  Mar 13 '15 at 20:52
  • 3
    UITextViews normally don't have an intrinsic contentSize, so they can't be sized automatically. They are basically scrollViews, you have to tell AutoLayout how big the textView frame should be, it will only calculate its contentSize. But according to [this answer](http://stackoverflow.com/a/21287306/457406) you could try to set scrollEnabled to NO. – Matthias Bauch Mar 13 '15 at 21:23
  • Thanks! It works! Can you post it as an answer so I can accept it? –  Mar 13 '15 at 21:42
  • After struggling for hours for a solution i found your reply! Thanks, please make an answer!!! @MatthiasBauch – Zac Jul 11 '16 at 19:24

1 Answers1

3

if you set your UITextView to "not" scrollable:

[textView setScrollEnabled:NO];

it will be able to calculate an intrinsic size, thus allowing auto layout to move the other elements by itself, then it's up to you to setup the constraints right.

Majid Bashir
  • 558
  • 1
  • 4
  • 27