How to determine if a link was clicked inside a UITextView, Swift
I have implemented what I believe is a function from the UITextViewDelegate that is linked to the URLs used in the UITextView, however now the functions are called in my code.
This is the function I used from the delegate.
func textView(textView: UITextView!, shouldInteractWithURL URL: NSURL!, inRange characterRange: NSRange) -> Bool {
println("Link Selected!")
}
However, I used breakpoints and the code isn't even available at runtime? Is this the correct function or is there an alternative?
+3
source to share
2 answers
Your class might look something like this:
class MyClass: UITextViewDelegate {
@IBoutet weak var aTextView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
aTextView.delegate = self
}
// Delegate
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
// User click on a link in a textview
print("Link Selected!")
// True => User can click on the URL Ling (otherwise return false)
return true
}
}
0
source to share