我有一个标签栏控制器,它有两个不同的视图控制器 - 每个都有一个WKWebView .
这是在我的WebViewController中:(如果我需要将ID丢给其他webView,我基本上可以根据URL进行解密 .
HTMLSermonAudioController().webView.load(URLRequest(url: url))
是我试图访问其他类的webView以更改已加载的页面的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中,所以我很难访问它 . 感谢上帝的混合应用程序,因为一旦我克服了最后一道障碍,我就不用担心任何更快速的代码了 .
1 回答
我最终想弄清楚如何使用NotificationCenter
在其他控制器中: