中的字符串调用方法
我有一个html字符串来自API服务,例如:
<html><body><a href="testFunction" target = blank>link test</a>...</body></html>
请注意,我将HTML字符串放入Uilabel,而不是在UIWebView
中,在我的viewcontroller.swift中,我有一个函数:
func testFunction() {
print("I am here")
}
我需要的是如何在用户单击链接测试时如何调用函数测试功能?
谢谢,
首先将其设置为标签:
label.isUserInteractionEnabled = true
Tapgesture:
let tap = UITapGestureRecognizer(target: self, action:
#selector(self.testFunction(_:)))
self.label.addGestureRecognizer(tap)
功能:
func testFunction(_ sender: UITapGestureRecognizer) {
print("I am here")
}
也许您可以阅读本文:http://codelle.com/blog/2016/2/calling-methods-from-indods-from-ingods-ind-srings-in-swift/
使用 NSSELECTORFROMSTRING ,您可以调用字符串的方法。
另一个链接:从swift