UITextView does not show long text

My iOS app does not display long attributes. I have a table cell that contains this text. When the text is very long, the table view does not respond for a while, but the text does not appear when loading. All other cells are displayed in order. And textView works fine with small text strings.

Here is 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 inserted a long line here . I am debugging and str loading in thin form with the desired text.

What is wrong here? What is the maximum string length in a UITextView ?

EDIT: very strange, when you try to select in a text editor, the text is displayed in a magnifying glass. I posted a video here .

Is this a bug in a UITextView?

Here is a screenshot. Empty white below - textView. here is the screenshot

+6
source share
3 answers

This may have something to do with scrolling. If you show all the text (i.e. the Text view expands as much as it should be, as well as the table view cell), scrolling is performed according to the table view. If the text view is smaller, you need to scroll to see all the text - this can lead to a conflict with the table view, which also represents scrolling.

It has been suggested that you turned off scrolling the text view before adding the text attribute and then re-enabling it. If you display all the text in a table view, you can turn off text scrolling. In some cases, it will only work if scrolling is enabled. You should also check this feature.

+8
source

I also had this problem (= a very long text attribute did not display in a UITextView in an authorized UITableViewCell). I tried all the accepted answers from here and from this question: Did the UITextView not load / display large text? . No one worked.

However, I then found out that - in my case - it just works fine on the device. Therefore, if you are still struggling with such a problem, do not rely on iOS Simulator.

+2
source

The reason you UITextView is not displaying all the text is because it is too small, so it truncates the text corresponding to its frame. you can take the next step to show the whole text:

  • In your CustomUITableCell, override layoutSubView:

Use this function to calculate the size of the TextView that matches its contents [textView sizeThatFits: CGSizeMake (textView.frame.size.width, CGFLOAT_MAX)]. height

After that, calculate and install a new frame for TExtView (in the user settings uitableCell)

  • In the View: heightForCellAtIndexPath table, we calculate the new textView size (also the height of the cell), similar to the above, and return the right height for the cell.
0
source

Source: https://habr.com/ru/post/972268/


All Articles