kmiklas
kmiklas

Reputation: 13433

webViewDidFinishLoad not firing called working

(Swift, iOS8, Xcode6, iPhone/iPad)

webViewDidFinishLoad is not being called, is not firing, and is not working.

Yes, I have set the containing view controller as the delegate. I CTRL-mousedowned on the UIWebView, dragged up to the little yellow circle representing the view controller, and released. A right-click on the UIWebView object shows that the delegate is set.

Yes, I did implement UIWebViewDelegate in my class declaration, like so:

class Paragraph: UIViewController, UIWebViewDelegate {

Yes, I did restart Xcode, and test on both the simulator and an actual iPhone 4S.

The request looks like this:

@IBOutlet var paragraph : UIWebView = nil

var r = NSBundle.mainBundle().pathForResource("cheddar", ofType: "htm")
var u = NSURL(fileURLWithPath: r)
paragraph.loadRequest(NSURLRequest(URL: u))

The callback function looks like this:

func webViewDidFinishLoad() {
    println("webViewDidFinishLoad")
}

Upvotes: 3

Views: 6296

Answers (1)

kmiklas
kmiklas

Reputation: 13433

I got it. The callback was missing a parameter. For posterity:

func webViewDidFinishLoad(webView: UIWebView!) {

Note the webView: UIWebView! parameter

In this case, perhaps even more important, is the way I found the bug. I created an entirely new view controller, and pieced it back together, carefully checking at each step to make sure that I didn't miss anything.

When the Intellisense popup showed the function with the parameter, I saw my error.

NOTE: In Swift 2.2, the UIWebViewDelegate protocol specifies a different optionality: webView: UIWebView. webView: UIWebView! spawns a warning.

Upvotes: 4

Related Questions