Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

WKWebview is nil even though it is hooked to storyboard

I have a WKWebview that is if course hooked up to the file through storyboard. You can see it is hooked in this picture:

enter image description here

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

As you see both in storyboard and in the UIViewController file, the webView is hooked.

I get a nil from the webViewthe first time I call it in the viewDidLoadon line 36.

enter image description here

This is the error:
Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

How can I get Xcode to recognize there is a web view??

EDIT
I load the VC like this:

let vc = joinFromInAppViewController()
vc.purchaseDate = purchaseDate
vc.purchaseEndDate = purchaseEndDate
vc.membershipPurchased = membershipPurchased
self.present(vc, animated: true, completion: nil)

The ViewController where the webView is in:

import UIKit
import WebKit
import RevealingSplashView
import SwiftEntryKit

class joinFromInAppViewController: UIViewController, WKNavigationDelegate {
    
    @IBOutlet weak var webView: WKWebView!
    
    var purchaseDate: Int = 0
    var purchaseEndDate: Int = 0
    var membershipPurchased: String = ""
    
    let revealingSplash = RevealingSplashView(iconImage: #imageLiteral(resourceName: "RevealingSplashIconImage"), iconInitialSize: CGSize(width: 125, height: 125), backgroundColor: UIColor(red: 225/255, green: 32/255, blue: 62/255, alpha: 1.0))
        
    var attributesShow = EKAttributes.bottomFloat
        
    let defaults = UserDefaults.standard
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(revealingSplash)
        revealingSplash.animationType = SplashAnimationType.heartBeat
        
        let myURL = URL(string: "https://www.google.com")
        let myRequest = URLRequest(url: myURL!)
        webView.navigationDelegate = self
        webView.load(myRequest)
        
        //revealingSplash.startAnimation()
        
    }
}

>Solution :

Set an id to the vc inside storyboard and load it like this

let vc = storyboard!.instantiateViewController(withIdentifier: "Id") as! IoinFromInAppViewController
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading