UIWebView not loading URL when URL is passed from UITableView

Posted by Mark Hazlett on Stack Overflow See other posts from Stack Overflow or by Mark Hazlett
Published on 2010-03-17T19:51:14Z Indexed on 2010/03/17 20:11 UTC
Read the original article Hit count: 732

Hey Everyone,

So i'm building a webView into my application to show the contents of a URL that I am passing from a selection in a UITableView. I know the UIWebView is loading content properly because if you hard code say http://www.google.ca into the NSURL then it loads fine, however when I'm passing the URL that I parsed from an RSS feed back from the UITableView it won't load the URL properly. I tried the debugger and the URL is coming out as nil right before I try and parse it, however I can use NSLog to print the value of it out to the console.

here's the code in my UIViewController that has my UIWebView

 #import <UIKit/UIKit.h>


@interface ReadFeedWebViewController : UIViewController 
{
    NSString *urlToGet;
    IBOutlet UIWebView *webView;
}

@property(nonatomic, retain) IBOutlet UIWebView *webView;
@property(nonatomic, retain) NSString *urlToGet;

@end

Here's the code for my implementation's viewDidLoad method...

    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad 
{
    [super viewDidLoad];

    NSLog(@"Url inside Web View Controller - %@", urlToGet);
    NSURL *url = [NSURL URLWithString:urlToGet];

    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [self.webView loadRequest:requestObj];
}

Once again, I can print the URL to NSLog fine and if I hard code the URL into the NSURL object then it will load fine in the UIWebView. Here is where I'm setting the value in my UITableViewController...

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{   
    ReadFeedWebViewController *extendedView = [[ReadFeedWebViewController alloc] init];

    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    extendedView.urlToGet = [[stories objectAtIndex: storyIndex] objectForKey:@"link"];
    //NSLog([[stories objectAtIndex: storyIndex] objectForKey:@"summary"]);
    NSLog([[stories objectAtIndex: storyIndex] objectForKey:@"link"]);

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

[extendedView release]; }

However, since I can print the value using NSLog in the extendedView view controller I know it's being passed properly. Cheers

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone