Reputation: 77646
I have a UITextView on the screen. This UITextView is covered by a UIView.
When I set the text for this UITextView, if the textView is not visible (UIView is covering it), it doesn't draw the text.
So when I remove the view that is covering my textView there is no text in my textView. If I try scrolling the textview the text will appear suddenly.
any way to force the UITextView to draw the text at all times? (This only happens when I have too much text in it (about 1000 characters))
I tried calling [textView setNeedsDisplay]
, before and after setting 'text' and it didn't fix the problem
Upvotes: 3
Views: 6232
Reputation: 3757
Since UITextView is a subclass of UIScrollView, I did something like this:
CGPoint offset = self.textView.contentOffset;
offset.y++;
[self.textView setContentOffset:offset];
offset.y--;
[self.textView setContentOffset:offset];
the same as @Tùng Đỗ without changing the frame... still looks ugly.
Upvotes: 0
Reputation: 93
Same problem. We have a textview that is configured and put into the view while hidden or offscreen. Most likely due to Apple optimizing UITextView
so that it doesn't do layout and drawing unless it is onscreen and visible.
Calling setNeedsDisplay
doesn't work because of the optimizations. setNeedsDisplay
gets called quite often, so imagine a UITextView
doing layout and drawing quite often? Thus the solution above is ugly but works: add a pixel to the frame which will trigger the UITextView
to re-layout and redraw. We went with this solution.
Upvotes: 0
Reputation: 1533
I have the same problem, my UITextView does not draw text until I try scrolling it or its parent. [textView setNeedsDisplay] does not work for me. Finally, I increase textView 1px and the problem's gone.
CGRect frame = textView.frame;
frame.size.height += 1;
textView.frame = frame;
I know this method is ugly but it does work.
Upvotes: 4
Reputation: 75077
Most things in the system will not display when hidden, which would be a waste of resources.
The correct approach is to call setNeedsDisplay: on the UITextView AFTER it has been un-hidden, then it should draw immediatley.
Upvotes: 1
Reputation: 8515
The limit to the number of characters in a UITextView
seems to be around relatively low (see the post here).
The poster in the link I posted suggests putting your content into a UIWebView
, which can handle a large amount of text.
Upvotes: 0