我是iOS开发的新手,现在正在开发一个接收某种JSON数据的应用程序.但是一些后端专家认为,如果用户只是直接从Word中复制信息并将其粘贴到信息系统中,对用户来说会更好.所以我坐在这里,尝试在UITableView中创建一个可点击的链接.
我从Web解析数据并获得具有以下格式的String:
Für mehr Informationen klicken sie <a href="http://www.samplelink.com/subpage.php?id=8">here</a>.
Run Code Online (Sandbox Code Playgroud)
我已经尝试了UILabel,但经过一些研究后我现在使用经常建议的UITextView.在Attributed Inspector中,我将其设置为属性文本并启用链接检测.现在文本显示为红色且可单击.
现在的问题是,HTML标签和正确的(德国)字符集仍然缺失,我不知道如何以正确的方式显示它.
显示的字符串以这种方式解析:
func showHTMLString(unformattedString: String) -> NSAttributedString{
var attrStr = NSAttributedString(
data: tmpString.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil,
error: nil)
return attrStr!
}
Run Code Online (Sandbox Code Playgroud)
如果我填写Textview,attrStr?.string格式以正确的方式显示,但链接也消失了.
有什么建议如何以正确的方式格式化显示的字符串?
在此先感谢AR4G4