1

I have a UIWebView in my view controller and have set its delegate to the view controller via code (i.e. not through IB). I have also setup the appropriate delegate methods: shouldStartLoadWithRequest, webViewDidStartLoad, webViewDidFinishLoad and didFailLoadWithError.

In my view controller's viewDidLoad method I load an appropriate URL with this code:

[self.webView loadRequest:reqURL];

95% of the time everything works great and the page loads in the UIWebView object and displays as expected. Occasionally, however, the page doesn't load.

After stepping through my code I realized that on the times that it doesn't work the shouldStartLoadWithRequest delegate method fires, but webViewDidStartLoad doesn't.

Does anyone have any idea what's going on here? I couldn't find anything on Stack Overflow that specifically addressed this unique issue I'm having and am slowly reaching my breaking point. Thanks in advance!

Cezar
  • 55,636
  • 19
  • 86
  • 87
Art Geigel
  • 1,915
  • 3
  • 22
  • 24
  • Is there any condition at which you `shouldStartLoadWithRequest`implementation doesn't return `YES`? – Cezar Mar 24 '13 at 03:10
  • Good point... I actually don't return YES in shouldStartLoadWithRequest and will update my code to do that. But even though I didn't have it returning YES it still loads the web content on the times it does work. – Art Geigel Mar 24 '13 at 03:16
  • Why it does work even though you didn't always return `YES` is something I don't really know. But I believe it might be a good lead to explain the inconsistent behavior. Anyway, can you share your implementation of `shouldStartLoadWithRequest`? – Cezar Mar 24 '13 at 03:22
  • Dude, you rock! I have been testing tons since you suggested I return YES and things are working perfectly. If you want to submit that as an answer I'll mark it as accepted. Thanks for your help. – Art Geigel Mar 24 '13 at 03:46
  • If this is the case and you forgot to put the `return YES` in than you should have been given a warning that says something like `warning: control reaches end of non-void function` did you not just look at the warning? – Popeye Mar 24 '13 at 10:36

1 Answers1

4

You should make sure that your shouldStartLoadWithRequest implementation returns YES for all conditions at which you need your webView to load.

Cezar
  • 55,636
  • 19
  • 86
  • 87