代码之家  ›  专栏  ›  技术社区  ›  wittich Manish Shrivastava

swift 3-未调用declated函数

  •  -1
  • wittich Manish Shrivastava  · 技术社区  · 8 年前

    Switf 3 在…上 Xcode 8 现在,我被一个小应用程序卡住了,它基本上只是在一个窗口中显示一个网页 webView 要素我试图实现的唯一附加功能是,外部URL作为共享应用程序(例如Safari)打开。

    因为有很多例子 SO func webView 它检查 url 没有接到电话。

    这是我的代码表 ViewController.swif 到目前为止:

    import UIKit
    
    class ViewController: UIViewController, UIWebViewDelegate {
    
        @IBOutlet weak var webView: UIWebView!
        override func viewDidLoad() {
            super.viewDidLoad()
            self.webView.delegate = self;
            let url = URL(string: "https://stackoverflow.com")
            debugPrint(url!)
            webView.loadRequest(URLRequest(url: url!))
        }
    
        // [...]
    
        func webView(webView: UIWebView!, shouldStartLoadWithRequest request: URLRequest!, navigationType: UIWebViewNavigationType) -> Bool {
            debugPrint("func webView has been called")
            debugPrint(request.url!)
            if navigationType == UIWebViewNavigationType.linkClicked {
                if (request.url!.host! == "stackoverflow.com"){
                    return true
                } else {
                    //UIApplication.sharedApplication().openURL(request.URL!)
                    UIApplication.shared.open(request.url!)
                    return false
                }
            }
            return true
        }
    }
    

    我的物流错误在哪里?

    2 回复  |  直到 8 年前
        1
  •  1
  •   vadian    8 年前

    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool
    
        2
  •  1
  •   Kamlesh Shingarakhiya    8 年前

    试试这个

    编辑

    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
            debugPrint("func myWebView has been called")
            debugPrint(request.url!)
            if navigationType == UIWebViewNavigationType.linkClicked {
                if (request.url!.host! == "stackoverflow.com"){
                    return true
                } else {
                    //UIApplication.sharedApplication().openURL(request.URL!)
                    UIApplication.shared.open(request.url!)
                    return false
                }
            }
            return true
        }