我正在使用此代码剪切
var htmlToAttributedString: NSAttributedString? { guard let data = data(using: .utf8) else { return NSAttributedString() } do { return try NSAttributedString(data: data,options: [.documentType: NSAttributedString.DocumentType.html,.characterEncoding:String.Encoding.utf8.rawValue],documentAttributes: nil) // Get crash on this line } catch let error { print(error.localizedDescription) return NSAttributedString() } } var htmlToString: String { return htmlToAttributedString?.string ?? "" }
在UITableViewCell中显示HTML文本
cell.textViewMessage.attributedText = msg.htmlToAttributedString
第一次启动没有崩溃,但在那之后,当我运行代码时崩溃并且之后没有工作.
Thread 1: EXC_BAD_ACCESS (code=1,address=0x10)
#Edit HTML要在单元格中显示的字符串
<p>Here\'s a short video tour. Press play to start.</p><br><iframe class=\"ql-video\" frameborder=\"0\" allowfullscreen=\"true\" src=\"https://www.youtube.com\"></iframe><br>
#Edit 1 – 我试图在Playground中运行此代码并且它正常工作,除非它现在显示错误.请参阅附图
解决方法
看起来问题是标记,而不是每个标记都可以在uitextview中显示.
您可以在uiwebview中更好地显示这些标记
您可以在uiwebview中更好地显示这些标记
我认为问题是iframe标签.
要显示iFrame,请使用uiwebview或wkwebview.
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。