Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView doesn't show until it is scrolled

I am using a UITextView to display the text from a xml.I parsed the xml and stored the text in a NSArray and from there i am adding it to a UITextview in my code.

problem: When i run the code the textview shows as empty or with partial text,and when i try to scroll the textview the whole text is getting displayed.

I added the UITextview to a UIView.

i found it strange and googled it but could not find many answers which helps me. Can someone reply me to solve the issue

TNQ

like image 832
Dinakar Avatar asked Oct 12 '11 10:10

Dinakar


3 Answers

Found a simple SOLUTION

Had the same problem. When you put text into a UITextView which is not visible, it doesn't draw the text.

I had my UITextView off screen and animated it in like this:

    [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations:^{
    self.contentView.center = CGPointMake(self.contentView.center.x + move * (self.contentView.frame.size.width /2), self.contentView.center.y);
    self.textView.frame = self.textView.frame; // <<<--- ADD THIS LINE
    } completion:^(BOOL finished) {
    if (finished) {
    }
}];

When you re-set the textview's frame, it re-draws it's text. So all you need to do is add the line I marked above before your UITextView comes on screen.

Cheers

like image 121
wolfrevo Avatar answered Nov 15 '22 19:11

wolfrevo


UITextView inherits from UIScrollView, so just scroll it.

[detailsTextView setContentOffset:CGPointMake(0, 1) animated:YES];
like image 21
aimless Avatar answered Nov 15 '22 20:11

aimless


i solved the issue by clearing the textview and added the text to the textview again,i dont know the exact funda but my issue is solved. in my case: i am changing the frame of the textview from outside to the view on click of a button.while the button is clicked the textview is not showing content and on scroll it shows.

i solved, by deleting the text from textview and re entering the text on clicking the button.

like image 40
Dinakar Avatar answered Nov 15 '22 19:11

Dinakar