Search code examples
iphonexcodeuikituiwebviewdelegate

shouldStartLoadWithRequest not loading links when clicked on in UIWebView


I've started using shouldStartLoadWithRequest and been encountering puzzling behaviour as I understand things. In it's most simplest form I've tried the following...

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{
  return YES;
}

With the side effect of when I click on HTML links the links do not load new pages in the UIWebView. Very likely I am not understanding something completely here. Any feedback/help would be greatly appreciated.


Solution

  • Two Possible reason

    1> either you have not set the delegate Set delegate your webview to your class i.e in viewDidLoad method

    webView.delegate = self; 
    

    (if webView is taken in xib file you need to set the delegate from sib file)

    2> your class does not implement UIWebViewDelegate protocol i.e. in your interface's declaration you haven,t declare it like this

    @interface RootViewController : UIViewController<UIwebViewDelegate>