gpt4 book ai didi

swift - 与 UITextView 中的空格建立链接 - iOS Swift

转载 作者:行者123 更新时间:2023-11-28 08:26:57 28 4
gpt4 key购买 nike

我有一个带有可点击链接的 UITextView。链接是通过在文本中搜索 placesArray 中包含的某些单词或短语来创建的,如下所示:

for place in placesArray {
let range = (text as NSString).range(of: place)
attributedText.addAttribute(NSFontAttributeName, value: UIFont(name:"Helvetica-Bold", size:16.0)!, range: range)
attributedText.addAttribute(NSLinkAttributeName, value: place, range: range)
}

一切正常,除非链接是由其中包含空格的短语创建的,例如“加利利海”。当我单击此链接时,应用程序崩溃了。调试窗口中没有显示任何内容,但我确实在我的 AppDelegate 中看到“线程 1:EXC_BREAKPOINT(代码=1,子代码=0x1007efc14)”。我该如何解决这个问题?

最佳答案

place.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)或制作可链接的网址(删除空格或其他)

关于swift - 与 UITextView 中的空格建立链接 - iOS Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39708341/

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