0
我有一个选项卡栏控制器,它有两个不同的视图控制器 - 每个控制器都带有一个WKWebView。从另一个类访问webView Swift 3
这是我WebViewController内:(我基本可以破译基于URL,如果我需要的ID扔给其他webView的
HTMLSermonAudioController().webView.load(URLRequest(url: url))
是我试图去访问的部分。其他类的web视图改变已加载页面的URL。
if requestURL.absoluteString.hasPrefix("bocaudio://?url="){
let url = URL(string: "https://storage.googleapis.com/boc-audio/123.mp3")!
HTMLSermonAudioController().webView.load(URLRequest(url: url))
tabBarController?.selectedIndex = 3
}
我也尝试使用内HTMLSermonAudioController等各种方法的类功能上面,但我似乎无法访问
import UIKit
import WebKit
class HTMLSermonAudioController: UIViewController, WKNavigationDelegate {
var webView: WKWebView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
let url = URL(string: "https://www.boc.domain/audioapp/290/")!
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
}
class func test(){
let url = URL(string: "https://www.boc.domain/audioapp/290/")!
HTMLSermonAudioController().webView.load(URLRequest(url: url))
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
title = webView.title
}
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
decisionHandler(.allow)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
因为Webview是在覆盖FUNC的loadView,这对我来说很难对其进行访问。感谢上帝提供混合应用程序,因为只要我克服了这个最后的障碍,我就不用担心任何更快的代码。