gpt4 book ai didi

ios - 快速在 UITextView 或 UILabel 中显示 html 数据

转载 作者:可可西里 更新时间:2023-11-01 01:06:28 25 4
gpt4 key购买 nike

如何在 UITextView 或 UILabel 中显示 html 数据,有一些方法可以工作,但需要花费大量时间来加载和滚动

cell.textView.attributedText = NSAttributedString(
data: comments.commentBody.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil,
error: nil)

最佳答案

如果问题只是加载缓慢,尝试在副线程中使用 dispatch_async 异步进行网络请求,然后在主线程中更新 UI(强制!)

let commentsQueue:dispatch_queue_t = dispatch_queue_create("comments queue", nil)

dispatch_async(commentsQueue, {

let commentsRequested = NSAttributedString(
data: comments.commentBody.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil,
error: nil)

dispatch_async(dispatch_get_main_queue(), {
cell.textView.attributedText = commentsRequested
})
})

关于ios - 快速在 UITextView 或 UILabel 中显示 html 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27796083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com