Reputation: 123
I am trying to check if the web view is loading and if its finish loading and when I try to search on it this is what I have gotten however it seems like it's not working is it because I have done something wrong or they change the code for it? I did set the delegate for the web view so I don't think the issue is with the delegate.
@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var activity: UIActivityIndicatorView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://stackoverflow.com")
let urlRequest = URLRequest(url: url!)
webView.loadRequest(urlRequest)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func webViewDidStartLoad(_ webView: UIWebView){
print("Webview started Loading")
}
func webViewDidFinishLoad(_ webView: UIWebView) {
print("Webview did finish load")
}
Upvotes: 1
Views: 3287
Reputation: 415
You need to add "delegate" in your UIWebView
webView.delegate = self
Upvotes: 0
Reputation: 2348
You need to conform your class to UIWebViewDelegate and delegate managing of webView to your class:
class YourClass: UIViewController, UIWebViewDelegate {
@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var activity: UIActivityIndicatorView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://stackoverflow.com")
//!!!!!!!
webView.delegate = self
//!!!!!!!
let urlRequest = URLRequest(url: url!)
webView.loadRequest(urlRequest)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func webViewDidStartLoad(_ webView: UIWebView){
print("Webview started Loading")
}
func webViewDidFinishLoad(_ webView: UIWebView) {
print("Webview did finish load")
}
}
Upvotes: 1