1. <small id='3paOh'></small><noframes id='3paOh'>

    2. <i id='3paOh'><tr id='3paOh'><dt id='3paOh'><q id='3paOh'><span id='3paOh'><b id='3paOh'><form id='3paOh'><ins id='3paOh'></ins><ul id='3paOh'></ul><sub id='3paOh'></sub></form><legend id='3paOh'></legend><bdo id='3paOh'><pre id='3paOh'><center id='3paOh'></center></pre></bdo></b><th id='3paOh'></th></span></q></dt></tr></i><div id='3paOh'><tfoot id='3paOh'></tfoot><dl id='3paOh'><fieldset id='3paOh'></fieldset></dl></div>
        <bdo id='3paOh'></bdo><ul id='3paOh'></ul>

    3. <tfoot id='3paOh'></tfoot><legend id='3paOh'><style id='3paOh'><dir id='3paOh'><q id='3paOh'></q></dir></style></legend>

      如何加载 Web 视图中的 url 链接并将其保留在 SWIFT 中的该 Web 视图中

      时间:2023-10-21
          • <legend id='0J3To'><style id='0J3To'><dir id='0J3To'><q id='0J3To'></q></dir></style></legend>

            <i id='0J3To'><tr id='0J3To'><dt id='0J3To'><q id='0J3To'><span id='0J3To'><b id='0J3To'><form id='0J3To'><ins id='0J3To'></ins><ul id='0J3To'></ul><sub id='0J3To'></sub></form><legend id='0J3To'></legend><bdo id='0J3To'><pre id='0J3To'><center id='0J3To'></center></pre></bdo></b><th id='0J3To'></th></span></q></dt></tr></i><div id='0J3To'><tfoot id='0J3To'></tfoot><dl id='0J3To'><fieldset id='0J3To'></fieldset></dl></div>
              <tbody id='0J3To'></tbody>
            • <bdo id='0J3To'></bdo><ul id='0J3To'></ul>
              <tfoot id='0J3To'></tfoot>

              <small id='0J3To'></small><noframes id='0J3To'>

              • 本文介绍了如何加载 Web 视图中的 url 链接并将其保留在 SWIFT 中的该 Web 视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个网页视图,它的网页底部带有链接.我有办法处理它们被点击,但它所做的只是将它们打开到一个新的 safari 浏览器中.这不是我想要的.我希望他们留在 Web 视图中并允许我像那样轻松地导航它们.有没有办法做到这一点?

                I have a web view that has a webpage with links at the bottom. I have a way to deal with them being clicked, but all it does is open them into a new safari browser. This is not what I want.I would like for them to stay inside the web view and allow me to navigate them easily like that. Is there a way to do this?

                我尝试过只使用常规的 Web 视图,但底部的链接不起作用.

                I have tried just using a regular web view, but then the links at the bottom will not work.

                这是我目前所拥有的:

                class ViewController: UIViewController, UIWebViewDelegate {
                
                
                @IBOutlet weak var myWebview: UIWebView!
                @IBOutlet weak var returnButton: UIButton!
                
                override func viewDidLoad() {
                    super.viewDidLoad()
                
                    prettyReturnButton(returnButton)
                
                    let url = NSURL(string: "mywebpage")
                
                    myWebview.delegate = self
                
                    print("Web page:" , url)
                    let requestObj = NSURLRequest(URL: url!);
                    myWebview.loadRequest(requestObj);
                    myWebview.keyboardDisplayRequiresUserAction = true
                
                
                
                }
                
                func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
                    switch navigationType {
                    case .LinkClicked:
                        // Open links in Safari
                        //let newRequestObj = NSURLRequest(URL: request.URL!)
                       // webView.loadRequest(newRequestObj)
                        UIApplication.sharedApplication().openURL(request.URL!)
                        return false
                    default:
                        // Handle other navigation types...
                        return true
                    }
                }
                

                推荐答案

                在 webview 委托中,您将希望使用相同的 webview 导航到新的 url.

                In the webview delegate you are going to want to navigate to the new url using that same webview.

                对您而言,这意味着您应该在您的开关盒内使用loadRequest

                For you this means that inside your switch case you should use loadRequest

                loadRequest 文档

                要解决您的问题,您应该使用 UIApplication.sharedApplication().openURL(request.URL!)

                To fix your issue you should remove the line using UIApplication.sharedApplication().openURL(request.URL!)

                并将其替换为对 loadRequest

                func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
                    switch navigationType {
                
                    case .LinkClicked:
                        // Open links in Safari
                
                        guard let newRequest = request as? URLRequest else { return false }
                
                        webView.loadRequest(newRequest)
                        return false
                    default:
                        // Handle other navigation types...
                        return true
                   }
                }
                

                希望这会有所帮助!祝你有美好的一天!

                Hope this helps! Have a nice day!

                这篇关于如何加载 Web 视图中的 url 链接并将其保留在 SWIFT 中的该 Web 视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 webView 中赋予页面卷曲动画? 下一篇:iphone:如何在 iPhone 电子书应用程序中添加电子邮件功能

                相关文章

                <i id='2rNex'><tr id='2rNex'><dt id='2rNex'><q id='2rNex'><span id='2rNex'><b id='2rNex'><form id='2rNex'><ins id='2rNex'></ins><ul id='2rNex'></ul><sub id='2rNex'></sub></form><legend id='2rNex'></legend><bdo id='2rNex'><pre id='2rNex'><center id='2rNex'></center></pre></bdo></b><th id='2rNex'></th></span></q></dt></tr></i><div id='2rNex'><tfoot id='2rNex'></tfoot><dl id='2rNex'><fieldset id='2rNex'></fieldset></dl></div>

                <small id='2rNex'></small><noframes id='2rNex'>

                <tfoot id='2rNex'></tfoot>
                    <bdo id='2rNex'></bdo><ul id='2rNex'></ul>
                    <legend id='2rNex'><style id='2rNex'><dir id='2rNex'><q id='2rNex'></q></dir></style></legend>