Vis*_*l16 9 html uitextview ios swift swift4
我正在使用此代码剪切
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 ?? ""
}
Run Code Online (Sandbox Code Playgroud)
显示HTML文本UITableViewCell
cell.textViewMessage.attributedText = msg.htmlToAttributedString
Run Code Online (Sandbox Code Playgroud)
启动第一次没有崩溃,但在那之后,当我运行代码时崩溃并且之后没有工作.
线程1:EXC_BAD_ACCESS(代码= 1,地址= 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>
Run Code Online (Sandbox Code Playgroud)
#Edit 1 - 我试图在Playground中运行此代码并且它正常工作,除非它现在显示错误.请参阅附图
小智 5
看起来问题是标记,而不是每个标记都可以在uitextview中显示.您可以在uiwebview中更好地显示这些标记
我认为问题是iframe标签.
要显示iFrame,请使用uiwebview或wkwebview.
谢谢
| 归档时间: |
|
| 查看次数: |
768 次 |
| 最近记录: |