1
votes

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!

1
Is there any condition at which you shouldStartLoadWithRequestimplementation doesn't return YES? - Cezar
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
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
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
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

1 Answers

4
votes

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