I use UITextView to display rtf text loaded from a file. The text has links in it. Tapping a link opens the correct page in Safari. Then I go back to my app. When I tap another link, or even the same one, nothing happens. Is there some kind of reset that I have to invoke on UITextView to make this behave correctly?
UITextView only follows links once
Could you show the full code ?
And show the rtf text in plain format. Maybe a problem with the embedded links themselves ?
Did you set the text as attributedString ?
Did you use shouldInteractWith ?
Short tutorial here, to check you did all that's needed:
https ://www.youtube .com/watch?v=qr1XJMIziBg
And show the rtf text in plain format. Maybe a problem with the embedded links themselves ?
Did you set the text as attributedString ?
Did you use shouldInteractWith ?
Code Block optional func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool
Short tutorial here, to check you did all that's needed:
https ://www.youtube .com/watch?v=qr1XJMIziBg
I'm working in code, not IB, so I'm not sure everything in the video applies. I create my text with the link in TextEdit, then import it into NSAttributedString. And it works... once.
Nevertheless, I just changed my code to make the UITextView selectable, as suggested in the video. And I implemented the method with the complicated name. Upon testing: no difference in behavior. BTW the method with the complicated name is never invoked, nor do I see why it would be. Even without that method, the link is taken once.
OK, I just saw your edit. I have now made my VC implement UITextViewDelegate and set itself as the delegate. And I haven't set up the other method you mention. What is the code inside that method?
Looking further into textView(UITextView,shouldInteractWith:URL,in:NSRange,interaction:UITextItemInteraction)->Bool,
it looks like the video code is doing things it doesn't need to do. All that method needs to do is return true. At this point, the method is invoked in my code, but only once. The doc for that method says something in Discussion about only being invoked once, but its example is not clear.
So I am back to thinking this is some invisible undocumented state issue within UITextView.
Nevertheless, I just changed my code to make the UITextView selectable, as suggested in the video. And I implemented the method with the complicated name. Upon testing: no difference in behavior. BTW the method with the complicated name is never invoked, nor do I see why it would be. Even without that method, the link is taken once.
OK, I just saw your edit. I have now made my VC implement UITextViewDelegate and set itself as the delegate. And I haven't set up the other method you mention. What is the code inside that method?
Looking further into textView(UITextView,shouldInteractWith:URL,in:NSRange,interaction:UITextItemInteraction)->Bool,
it looks like the video code is doing things it doesn't need to do. All that method needs to do is return true. At this point, the method is invoked in my code, but only once. The doc for that method says something in Discussion about only being invoked once, but its example is not clear.
So I am back to thinking this is some invisible undocumented state issue within UITextView.