I added an activity indicator to my view controller via the main.storyboard and put it in my view controller via drag & drop method but when I try to do something with addSubView I get this error.
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
On the line: view.addSubview(ActInd)
The project is running on Swift 5.0 and Xcode 10.3. Switching back to Swift 4.2 makes no difference. I can debug the app but then it crashes when it comes to the piece of coding
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
var webView: WKWebView!
@IBOutlet weak var ActInd: UIActivityIndicatorView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
func loadPage(){
let url = URL(string: "SOMEURL")!
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
}
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(ActInd)
ActInd.startAnimating()
ActInd.hidesWhenStopped = true
loadPage()
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
// Code runs when its finnished
ActInd.stopAnimating()
}
}
I wanted to have an activity indicator when my page was loading in the webview