Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Offscreen UITextView invisible/clear text in iOS 5

I've got an off-screen UITextView instance loaded from a nib which is moved into the screen frame when the user taps a "comment" button. Any text the enter uses is invisible. If the user rotates the device, the text appears.

I've tried throwing setNeedsDisplay and setNeedsLayout, as well as setting the text, textColor, and font properties after it comes on screen with no luck.

I have an example Xcode project demonstrating the bug.

Any suggestions?

like image 231
Ash Furrow Avatar asked Nov 26 '22 08:11

Ash Furrow


2 Answers

I couldn't solve this problem so I wait until the view has finished animating on screen and recreate the UITextView, remove the old one, and replace it with the new one.

It's very inelegant since I even need to keep a BOOL ivar for remembering if I've already replaced the text view (or not).

like image 119
Ash Furrow Avatar answered Dec 21 '22 05:12

Ash Furrow


so the solution is to instantiate the UITextView in your code and add it as a subview when the textview needs to appear in the screen for the first time. Then you can make it disappear and reappear and it should be OK.

UITextView *aTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 89, 684, 441)];
[aTextView setFont:[UIFont systemFontOfSize:17.0]];
[addCommentView insertSubview:aTextView atIndex:1];
[self setCommentTextView:aTextView];
[aTextView release];

It's working great for me !

like image 38
Dabrut Avatar answered Dec 21 '22 05:12

Dabrut