0

I've created a progressView and linked it like this: progressview

And here is what I do in my view controller:

class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {

     @IBOutlet weak var progressView: UIProgressView!
     @IBOutlet weak var KronosWebsite: WKWebView!

     override func loadView() {
         //initialize the webview
         progressView = UIProgressView()
         
         progressView.progress = 1.0

         KronosWebsite = WKWebView()
         self.view = KronosWebsite
         self.view.addSubview(progressView)
     }
 }

And I've got

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional

in this line progressView.progress = 1.0

Community
  • 1
  • 1

2 Answers2

0

Add super.loadView() when you use loadView for a vc that originally inside storyboard

 override func loadView() {
     super.loadView() 

or insert all code inside viewDidLoad , also don't re-init

progressView = UIProgressView() 
KronosWebsite = WKWebView()

as they already initiated from storyboard

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

The docs say to never override loadView if your view controller comes from a storyboard or xib:

loadView()

If you use Interface Builder to create your views and initialize the view controller, you must not override this method.

Everything that you're currently doing in loadView can be done in the storyboard anyway, so just remove the loadView method and connect your UIProgressView and WKWebView to your outlets in your storyboard. You can also set the progress view's initial progress to 1.0 inside the storyboard.

Community
  • 1
  • 1
TylerP
  • 9,600
  • 4
  • 39
  • 43