Objective c UITextView中的Tappable链接将导航到另一个控制器
我正在通过单击textview中的url链接来导航屏幕 这是我的代码Objective c UITextView中的Tappable链接将导航到另一个控制器,objective-c,swift,uitextview,Objective C,Swift,Uitextview,我正在通过单击textview中的url链接来导航屏幕 这是我的代码 extension ViewController: UITextViewDelegate { func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool { print("
extension ViewController: UITextViewDelegate {
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
print("click event url:", URL)
let vc = storyboard?.instantiateViewController(withIdentifier: "blogsViewController") as! BlogsViewController
vc.url = URL.absoluteString
navigationController?.pushViewController(vc, animated: true)
return true
}
}
但此链接将打开到safari浏览器,而不是导航到特定的控制器。如果要打开另一个视图控制器而不是浏览器,则只能在委托方法中返回false
extension ViewController: UITextViewDelegate {
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
print("click event url:", URL)
let vc = storyboard?.instantiateViewController(withIdentifier: "blogsViewController") as! BlogsViewController
vc.url = URL.absoluteString
navigationController?.pushViewController(vc, animated: true)
return false //instead of true
}
}
这应该足以满足您的需要。如果要打开另一个视图控制器而不是浏览器,则只应在委托方法中返回false
extension ViewController: UITextViewDelegate {
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
print("click event url:", URL)
let vc = storyboard?.instantiateViewController(withIdentifier: "blogsViewController") as! BlogsViewController
vc.url = URL.absoluteString
navigationController?.pushViewController(vc, animated: true)
return false //instead of true
}
}
这应该足以达到你的目的