Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView not showing long text

My iOS app is not showing long attributed strings. I have a cell in a tableview which contains this textView. When the text is very long the tableview is unresponsive for a while but when it loads the text is not shown. All other cells are displayed fine. And the textView works fine with small text strings.

Here's the code:

            descriptionCell = [tableView dequeueReusableCellWithIdentifier:@"CellAdDetailDescription"];
            descriptionCell.bodyTextView.delegate = self;
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:self.ad.body];

            UIFont *cellFont;
            cellFont = [UIFont fontWithName:@"HelveticaNeue" size:16.0];

            NSDictionary *attributesDictionary;
            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
            paragraphStyle.lineSpacing = 10;

            attributesDictionary = @{NSParagraphStyleAttributeName : paragraphStyle , NSFontAttributeName: cellFont};

            [str addAttributes:attributesDictionary range:NSMakeRange(0, str.length)];
            descriptionCell.bodyTextView.attributedText = str;

I pasted the long string here. I debugged and str is being loaded fine containing the desired text.

Whats wrong here? What is the max allowed string length in UITextView?

EDIT: very odd, when trying selection in the textView, the text is being shown in the magnifying glass. I posted a video here.

Is it a bug in UITextView?

Here is the screenshot. The blank white at the bottom is the textView. here is the screenshot

like image 286
Abdullah Umer Avatar asked Jul 15 '14 21:07

Abdullah Umer


1 Answers

It could have something to do with the scrolling. If you are showing all the text (i.e. the text view is expanded to be as high as it needs to be, and so is the table view cell), the scrolling is done by the table view. If the text view is smaller, you have to scroll to see all the text - this might cause a conflict with the table view, which is also a scroll view.

It has been suggested that you disable the scrolling of the text view before adding the attributed text and reenable it afterwards. If you are showing the whole text in the table view, you can leave the text view scrolling disabled. In some cases, it will only work if scrolling is enabled. You should check this possibility as well.

like image 106
Mundi Avatar answered Sep 21 '22 08:09

Mundi