首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSAttributedString冷冻UITableView

NSAttributedString冷冻UITableView
EN

Stack Overflow用户
提问于 2015-02-03 12:47:13
回答 2查看 3.2K关注 0票数 5

应用程序在使用NSAttributedString滚动时真的会冻结(当我使用NSString时,它工作得很好),所以这里有我的方法:

代码语言:javascript
复制
- (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变得更快的方法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-03 12:59:48

我建议从NSAttributedString异步创建一次,并将属性化字符串存储在模型中。这样,您就不必在每个单元格重用上执行HTML属性化字符串转换,这在滚动时经常发生。

票数 7
EN

Stack Overflow用户

发布于 2017-12-05 21:43:33

异步地设置它(我认为问题是连接的,滚动视图也在使用主线程):

代码语言:javascript
复制
- (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];
        });
    });
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28299342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档