应用程序在使用NSAttributedString滚动时真的会冻结(当我使用NSString时,它工作得很好),所以这里有我的方法:
- (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];
}有什么错误吗?还是让att.string变得更快的方法?
发布于 2015-02-03 12:59:48
我建议从NSAttributedString异步创建一次,并将属性化字符串存储在模型中。这样,您就不必在每个单元格重用上执行HTML属性化字符串转换,这在滚动时经常发生。
发布于 2017-12-05 21:43:33
异步地设置它(我认为问题是连接的,滚动视图也在使用主线程):
- (void)setSubtitleForCell:(TTTableViewCell *)cell item:(TTPhotoPost *)item
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:
[item.caption dataUsingEncoding:NSUnicodeStringEncoding]
options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
documentAttributes:nil
error:nil];
dispatch_on_main_queue(^{
[cell.descriptionLabel setAttributedText:attributedString];
});
});
}https://stackoverflow.com/questions/28299342
复制相似问题