这是我的雨燕

     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,单击Link/按钮后,它将显示下一个带有tabbar的viewcontroller。

最佳答案

你试过打开链接吗?您应该收到func webView(UIWebView,shouldstartoadwith:URLRequest,navigationType:UIWebViewNavigationType)委托回调。在这里,您应该检查该链接是否触发了视图控制器的打开。如果是特殊链接,则打开viewController并返回false。否则返回真。

关于swift - 如何通过单击webView中的按钮来显示ViewController? Swift/Xcode,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41678765/

10-11 20:01
查看更多