1

I need to calculate the height for the cell in tableView:heightForRowAtIndexPath: The function for setting up the attributed text from html is very expensive:

[[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUnicodeStringEncoding] options:options documentAttributes:nil error:&error];

Creating the attributed string in forward in a background thread is not possible/solving the problem as the function uses some functionality from Webkit and can work only on the main thread.

I had to abandon the use of UITableView and used UIScrollView instead but then there is the issue with reusing the content views. It is managed for me in UITableView but tableView:heightForRowAtIndexPath: is really slow. I am using an off screen prototype cell (which can also include hierarchy of views - replies like in forum) to calculate the height with systemLayoutSizeFittingSize.

Also in the implementation with UITableView I used a dictionary with cached attributed strings but it was not that big gain in speed.

Vladimír Slavík
  • 1,727
  • 1
  • 21
  • 31
  • Hey did you find the solutions? – Developer Nov 03 '15 at 12:24
  • @Developer 1. Do not use just auto layout for calculating the rich text size. Calculate it directly with e.g. http://stackoverflow.com/a/14410019/3389683 Try to calculate as much as possible using frames. 2. I am using https://github.com/Cocoanetics/DTCoreText to render the text. It is much faster then solution based on the Webkit rendering. And it looks good. – Vladimír Slavík Nov 03 '15 at 14:35

0 Answers0