当点击UIWebView中的按钮时打开ViewController

编程入门 行业动态 更新时间:2024-10-25 23:27:57
本文介绍了当点击UIWebView中的按钮时打开ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I Have an app which has UIWebView and the Webview contains simple Button

以下是我的WebViewController:

and here's my 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: "mydomainname/index.html"); let requestObj = NSURLRequest(URL: url!); myWebView.loadRequest(requestObj); } }

而webView完美显示我的HTML

And the webView displaying my HTML perfectly

当我点击HTML文件中的按钮时,我只需要从我的iOS项目中提供一个newViewController?

I am just need to present a newViewController from my iOS project when i Click the button in my HTML file ?

这样:

like that :

<button onclick="myFunction()> Submit </button> <script> function myFunction() { presentViewController('myViewControllerName'); } </script>

有没有办法在iOS中做到这一点?

is there any way to do that in iOS ?

推荐答案

是的,你可以这样做:

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     }

更多推荐

当点击UIWebView中的按钮时打开ViewController

本文发布于:2023-06-09 04:13:31,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   UIWebView   ViewController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!