Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if a link, inside a UITextView has been clicked, Swift

Tags:

ios

swift

I have implemented what I think is the function from UITextViewDelegate, which deals with URLs being tapped in a UITextView, however the functions now being called in my code.

This is the function I have used from the delegate.

func textView(textView: UITextView!, shouldInteractWithURL URL: NSURL!, inRange characterRange: NSRange) -> Bool {

println("Link Selected!")

}

However I have used breakpoints and the code isn't even being accessed at runtime? Is this the correct function or is there an alternative?

like image 371
Stephen Fox Avatar asked Aug 17 '14 22:08

Stephen Fox


1 Answers

You need to make sure that the class implementing the delegate protocol is set as the delegate for the UITextView.

self.textView.delegate = self
like image 121
max_ Avatar answered Nov 10 '22 11:11

max_