在UITextView中显示HTML文本崩溃发生在swift 4中?

前端之家收集整理的这篇文章主要介绍了在UITextView中显示HTML文本崩溃发生在swift 4中?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_0@
我正在使用此代码剪切

  1. var htmlToAttributedString: NSAttributedString? {
  2. guard let data = data(using: .utf8) else { return NSAttributedString() }
  3. do {
  4. return try NSAttributedString(data: data,options: [.documentType: NSAttributedString.DocumentType.html,.characterEncoding:String.Encoding.utf8.rawValue],documentAttributes: nil) // Get crash on this line
  5. } catch let error {
  6. print(error.localizedDescription)
  7. return NSAttributedString()
  8. }
  9. }
  10.  
  11. var htmlToString: String {
  12. return htmlToAttributedString?.string ?? ""
  13. }

在UITableViewCell中显示HTML文本

  1. cell.textViewMessage.attributedText = msg.htmlToAttributedString

第一次启动没有崩溃,但在那之后,当我运行代码时崩溃并且之后没有工作.

Thread 1: EXC_BAD_ACCESS (code=1,address=0x10)

#Edit HTML要在单元格中显示的字符串

  1. <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中更好地显示这些标记

我认为问题是iframe标签.

显示iFrame,请使用uiwebview或wkwebview.

谢谢

猜你在找的HTML相关文章