加载WKWebViewController后,您将无法再次进行转换。

9 浏览
0 Comments

加载WKWebViewController后,您将无法再次进行转换。

我有以下的视图控制器

import Foundation

import UIKit

import WebKit

class TextViewController : UIViewController, WKNavigationDelegate {

var data: Book!

@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {

super.viewDidLoad()

self.navigationController?.navigationBar.isHidden = true

webView.navigationDelegate = self

if var body = self.data.body {

body += ""

webView.loadHTMLString(body, baseURL: nil)

}

}

override func viewWillAppear(_ animated: Bool) {

super.viewWillAppear(animated);

NetworkActivityIndicatorManager.networkOperationStarted()

LoadingIndicatorView.show("加载中")

self.tabBarController?.tabBar.isHidden = true;

self.navigationController?.navigationBar.isHidden = true

}

override func viewWillDisappear(_ animated: Bool) {

super.viewWillDisappear(animated);

self.tabBarController?.tabBar.isHidden = false;

}

@IBAction func goback(_ sender: UIButton) {

self.navigationController?.popViewController(animated: true)

}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {

let css = "body { font-size: 18px; line-height: 28px; } h1 { font-size: 34px; text-align: left; margin-bottom: 12px; line-height: 1.3; } h2 { font-size: 26px; font-weight: 700; padding: 0; margin-bottom: 10px; text-align: left; line-height: 34.5px; letter-spacing: -0.45px; } p, i, a { margin-top: 21px; font-size: 20px; letter-spacing: -0.03px; line-height: 1.57; }";

let js = "var style = document.createElement('style'); style.innerHTML = '\(css)'; document.head.appendChild(style);"

webView.evaluateJavaScript(js, completionHandler: nil)

NetworkActivityIndicatorManager.networkOperationFinished()

LoadingIndicatorView.hide()

}

}

当我切换到这个视图控制器时,它会加载webview。然而,当我通过触发goback操作退出视图控制器时,我无法返回到webview控制器。我错过了什么吗?这是我如何转场到控制器的方式 -

self.performSegue(withIdentifier: "toText", sender: nil)

0