Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSAttributedString freeze UITableView

Application really freeze while scrolling with NSAttributedString (When I use NSString it works fine), so there my method:

- (void)setSubtitleForCell:(TTTableViewCell *)cell item:(TTPhotoPost *)item
{
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:
                                            [item.caption dataUsingEncoding:NSUnicodeStringEncoding]
                                                                            options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
                                                                 documentAttributes:nil
                                                                              error:nil];

    [cell.descriptionLabel setAttributedText:attributedString];
}

Any mistakes there? or some way to make att.string faster?

like image 646
Zaporozhchenko Oleksandr Avatar asked Feb 03 '15 12:02

Zaporozhchenko Oleksandr


1 Answers

I'd suggest creating the NSAttributedString from HTML once asynchronously, and storing the attributed string in your model. That way you won't have to do the HTML -> attributed string conversion on every cell reuse, which happens a lot when you're scrolling.

like image 62
rounak Avatar answered Oct 22 '22 12:10

rounak