Iphone – UIWebView not showing/loading request

delegatesiphonerequestuiwebview

Good morning everyone,

I have an RSS reader tha opens a Detail view controller when a feed in tableView is clicked. The HTML of the feed is loaded from a items array like this in DetailController's custom setFeed() method:

[self.itemContent loadHTMLString:[NSString stringWithFormat:@"%@"[item objectForKey:@"content"]] baseURL:nil];

HTML gets loaded without any problems. If any link within is clicked the new request is loaded in the same UIWebView. The problem is that I want to show the web page in another UIWebView when a link inside itemContent is clicked.

So, what I did is I declared

itemContent.delegate = self 

and in the delegate class (self) defined following method:

 -(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {if (navigationType == UIWebViewNavigationTypeLinkClicked) {

    NSLog(@"Opening Outside link!!!\n");

    BrowserViewController *browserViewController = [[[BrowserViewController alloc] init] autorelease];

    //following line doesn't change anything in the result
    //browserViewController.webView.delegate = self;

    [browserViewController.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];

    [self.navigationController pushViewController:browserViewController animated:YES]; 

    return NO;

    }

return YES;

}

This method definitely recognizes between loading the HTML for the first time in itemContent from clicks performed on the links in itemContent webView.
NavigationController pushes to the next View but nothing s loaded in it. I mean I've put one label next to UIWebView in the NIB file of BrowserViewController just to be sure that the NIB is loaded by seeing the label; and its showing. Also, I defined an Outlet webView connected with the UIWebView in NIB file, so this shouldn't be the problem.

If its not clear what seems to be the problem is: when the link is clicked, browserViewController is presented with the label but webView doesn't load the request.

Please, if someone could check the code provided that would be great.

I wish you a very nice day,
L

Best Answer

When you put a NSLog(@"WebView: %@", browserViewController.webView); in front of your loadRequest call you will see that the webView is nil.

The webView is not available at this time. It wasn't created in the init method.

I would suggest to add a NSURL *url; property to your BrowserViewController. And then instead of [browserViewController.webView loadRequest:... you could use browserViewCOntroller.url = request.URL;. Or you could save the NSURLRequest directly.

And in the viewDidLoad method of the BrowserViewController you can tell the webview to load the URL, or the URLRequest.


But I'm just guessing.

Related Topic