gpt4 book ai didi

xcode - UITextViewDelegate 函数应该在 Xcode 8.0 中与 URL 交互

转载 作者:可可西里 更新时间:2023-11-01 00:05:26 28 4
gpt4 key购买 nike

我创建了一个带有可检测链接的 UITextView,但是我无法使用 UITextView 委托(delegate)函数“shouldinteractwithURL”。

我收到一条警告,指出该实例方法几乎与另一个实例方法匹配。我查看了委托(delegate)函数,'shouldinteractwithURL' 函数已针对 ios 10.0 进行了更新,但是我想使用与 ios 9 兼容的函数版本。但是,即使我使用新版本并设置部署目标到 ios 10,我得到了相同的警告并且函数仍然没有被调用(我已经正确发送了 textview 委托(delegate))。

Xcode 建议的解决方案是将函数设为私有(private)或添加@nonobjc。这些都不起作用,因此单击链接时没有任何反应。

有没有其他人遇到过这个问题,或者这是 Xcode 8.0 的问题?

最佳答案

通过添加@availability 属性,编译时不会出错:

//For iOS 7...9
@available(iOS, deprecated: 10.0)
func textView(_ textView: UITextView, shouldInteractWith url: URL, in characterRange: NSRange) -> Bool {
var result = false
//...
return result
}

//For iOS 10
@available(iOS 10.0, *)
func textView(_ textView: UITextView, shouldInteractWith url: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
var result = false
//...
return result
}

关于xcode - UITextViewDelegate 函数应该在 Xcode 8.0 中与 URL 交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38170591/

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