I'm using WKWebView to load content. That part of the code works fine. Now I want to add a toolbar: went to storyboard, added toolbar, added button in the toolbar. Hit run just to see the toolbar in the simulator and nothing!!
Code is below:
// Created by Matthew on 8/31/21.
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
//start code
let webView = WKWebView()
webView.uiDelegate = self
webView.navigationDelegate = self
let htmlURL = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "FILES")!
webView.loadFileURL(htmlURL, allowingReadAccessTo: htmlURL.deletingLastPathComponent())
view = webView
}
//Can't get toolbar to show on simulator. Can not test print button
@IBOutlet weak var Toolbar: UIToolbar!
@IBAction func BBI(_ sender: Any) { }
@IBAction func PrintPDF(_ sender: Any) {
let printController = UIPrintInteractionController.shared
let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = UIPrintInfo.OutputType.general
printInfo.jobName = (webView.url?.absoluteString)!
printInfo.duplex = UIPrintInfo.Duplex.none
printInfo.orientation = UIPrintInfo.Orientation.portrait
printController.printPageRenderer = nil
printController.printingItems = nil
printController.printingItem = webView.url!
printController.printInfo = printInfo
printController.showsNumberOfCopies = true
//printController.printFormatter = webView.viewPrintFormatter()
//printController.presentFromBarButtonItem(PrintPDF, animated: true, completionHandler: nil)
printController.present(animated: true, completionHandler: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// dispose of any resources that can be recreated
}
}
Post
Replies
Boosts
Views
Activity
I'm getting a question mark near my reference folder. Any idea why this would be happening??
The app builds and then spits out this error "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" by bundle.main.url
import UIKit
import WebKit
class ViewController: UIViewController {
@IBOutlet weak var loadhtml: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let webView = WKWebView()
let htmlURL = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "FILES")!
webView.loadFileURL(htmlURL, allowingReadAccessTo: htmlURL.deletingLastPathComponent())
view = webView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// dispose of any resources that can be recreated
}
}