I've run into an issue where a PDF that is correctly rendered disappears when switching to a different tab and then back to the original controller. The issue is easily reproducible using Xcode 10.1's Tabbed App template. I created a project using this template, and then placed the following code in SecondViewController (after removing the default subviews added by the template):
import UIKit
import WebKit
class SecondViewController: UIViewController {
private lazy var webView: WKWebView = {
let view = WKWebView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(webView)
webView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
webView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
webView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
let url = URL(string: "https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf")!
webView.load(URLRequest(url: url))
}
}
When launching the app and switching to the second tab, the PDF renders correctly. Then, after switching back to the first tab and then back to the second it shows just a gray background with no PDF content. You can still scroll through the document and it will show page numbers, etc. But no content.
Any help or suggestions would be appreciated.