0

There is an error in container.bounds where container is underlined because of unexpectedly found nil optional value

I Check the reference outlet and it's connected

What am i missing here ?

enter image description here enter image description here

public class testViewController: UIViewController {

    @IBOutlet weak var readyButton : Button!
    @IBOutlet weak var container: UIView!
    private var webView = WKWebView()
    public init() {
        super.init(nibName: "DetilSandKViewController", bundle: Bundle(for: DetilSandKViewController.self))
        
        self.modalPresentationStyle = .overCurrentContext
        self.modalTransitionStyle = .crossDissolve
    }
    
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    public override func viewDidLoad() {
        super.viewDidLoad()
       
        webView.frame = container.bounds
        webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        container.addSubview(webView)
        
       
        webView.scrollView.delegate = self
        // Do any additional setup after loading the view.
    }
    
    public override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        webView.scrollView.setContentOffset(.zero, animated: true)
        
    }


}
extension testViewController: UIScrollViewDelegate {
   
}
lauwis
  • 79
  • 7
  • I don't use storyboard much but believe your view controller hasn't loaded its view hierarchy yet. This usually should happen by `willLayoutSubviews / viewWillAppear`. What if you moved this code out of `viewDidLoad` to `viewWillAppear` for instance - does the crash still occur ? – Shawn Frank Mar 17 '22 at 10:31

0 Answers0