Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击UIWebView中的按钮时打开ViewController_Javascript_Html_Ios_Swift_Webview - Fatal编程技术网

Javascript 单击UIWebView中的按钮时打开ViewController

Javascript 单击UIWebView中的按钮时打开ViewController,javascript,html,ios,swift,webview,Javascript,Html,Ios,Swift,Webview,我有一个应用程序,它有UIWebView,Webview包含简单的按钮 这是我的WebViewController: import UIKit class testViewController: UIViewController { internal static var testID = 0 @IBOutlet weak var myWebView: UIWebView! override func viewDidLoad() { super.vie

我有一个应用程序,它有UIWebView,Webview包含简单的按钮

这是我的WebViewController:

import UIKit

class testViewController: UIViewController {
    internal static var testID = 0

    @IBOutlet weak var myWebView: UIWebView!
    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        let url = NSURL (string: "http://mydomainname/index.html");
        let requestObj = NSURLRequest(URL: url!);
        myWebView.loadRequest(requestObj);
    }
}
网络视图完美地显示了我的HTML

我只需要在单击HTML文件中的按钮时从iOS项目中显示一个新的ViewController

就像这样:

<button onclick="myFunction()> Submit </button>

<script>
function myFunction()
{
presentViewController('myViewControllerName');

}



</script>

您可以在js操作中分配方案:

window.location = yourscheme://<scheme_content>

是的,您可以这样做:

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        
        if (navigationType == UIWebViewNavigationType.FormSubmitted) {
            let VC = self.storyboard?.instantiateViewControllerWithIdentifier("myViewControllerName") as? myViewControllerName

            let navigationController = UINavigationController(rootViewController: VC!)
            self.navigationController?.presentViewController(navigationController, animated: true, completion:nil)

    
        }
        return true
    }

我的xcode错误:使用未声明的类型“myViewControllerName”哈哈大笑-我的xcode错误:使用未声明的类型“myViewControllerName”,因为您需要给出视图控制器名称,而不是“myViewController”,它只是一个示例名称
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        
        if (navigationType == UIWebViewNavigationType.FormSubmitted) {
            let VC = self.storyboard?.instantiateViewControllerWithIdentifier("myViewControllerName") as? myViewControllerName

            let navigationController = UINavigationController(rootViewController: VC!)
            self.navigationController?.presentViewController(navigationController, animated: true, completion:nil)

    
        }
        return true
    }