如何从webView中的按钮单击显示ViewController?Swift/Xcode
这是我的雨燕如何从webView中的按钮单击显示ViewController?Swift/Xcode,swift,webview,io,Swift,Webview,Io,这是我的雨燕 func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { if (navigationType == UIWebViewNavigationType.formSubmitted) { let VC = self.storyboard?
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if (navigationType == UIWebViewNavigationType.formSubmitted) {
let VC = self.storyboard?.instantiateViewController(withIdentifier: "UITabBarController") as? UITabBarController
let navigationController = UINavigationController(rootViewController: VC!)
self.navigationController?.present(navigationController, animated: true, completion:nil)
}
return true
}
这是我在webView中加载的HTML文件
<html>
<head>
<script>
function myFunction()
{
presentViewController('UITabBarController');
}
</script>
</head>
<body>
<input name="myFunction" type="submit" onClick="myFunction" value="myFunction">
</body>
</html>
这不管用,有什么建议吗?
我不介意它是链接而不是按钮
它是viewcontroller内部的webView,单击链接/按钮后,它将显示下一个带有选项卡栏的viewcontroller。您是否尝试打开链接?您应该收到func webViewUIWebView、shouldStartLoadWith:URLRequest、navigationType:UIWebViewNavigationType委托回调。在这里,您应该检查链接是否是触发视图控制器打开的链接。如果是特殊链接,您将打开viewController并返回false。否则返回true