I have the following view controller
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 += "<meta name=\"viewport\" content=\"initial-scale=1.0\" />"
webView.loadHTMLString(body, baseURL: nil)
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated);
NetworkActivityIndicatorManager.networkOperationStarted()
LoadingIndicatorView.show("Loading")
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()
}
}
When I transition to this view controller, it loads the webview. However, when I exit the view controller by triggering the goback action, I am unable to go back to the webview controller. I'm I missing something. Here's how I segue to the controller -
self.performSegue(withIdentifier: "toText", sender: nil)