-1

I have a html string come from the api service, for example :

<html><body><a href="testFunction" target = blank>link test</a>...</body></html>

Please note that I put the html string in UILabel and not in uiwebView

And in my ViewController.swift, I have a function :

func testFunction() {
  print("I am here")
}

What I need is how to call the function testFunction when the user click on the link test?

Thanks,

mplungjan
  • 169,008
  • 28
  • 173
  • 236

2 Answers2

0

At first set this to the label:

label.isUserInteractionEnabled = true

Tapgesture:

let tap = UITapGestureRecognizer(target: self, action: 
#selector(self.testFunction(_:)))
self.label.addGestureRecognizer(tap)

Function:

func testFunction(_ sender: UITapGestureRecognizer) {
     print("I am here")
}
Gregga17
  • 148
  • 7
0

Maybe you can read this article : http://codelle.com/blog/2016/2/calling-methods-from-strings-in-swift/

With NSSelectorFromString, you can call a method with a string.

Another link : Call a method from a String in Swift

kopacabana
  • 437
  • 3
  • 17