John Yen
John Yen

Reputation: 1

UIWebView - loading a page

I'm trying to load a link in a UIWebView that changes as the user selects different rows in the UITableView. Currently I'm using the code below and it's not working correctly.

I've based this on the sample code from an iOS Development book. That code can be found here. The sample code source"http://dl.dropbox.com/u/32355989/YoutubeVideoPlayer.zip"

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    
    NSString *youtubeURLString = [NSString stringWithFormat:@"http://www.youtube.com/v/%@",[videos objectAtIndex:indexPath.row]];
    NSString *html = [NSString stringWithFormat:YOUTUBE_HTML,youtubeURLString];

    [webView loadHTMLString:html baseURL:nil];  //<--This is the point.    
}

Does anyone know how to load the page correctly?

Upvotes: 0

Views: 169

Answers (1)

Mat
Mat

Reputation: 7633

Well, if you want to open a website in UIWebview you have to do smoething like this:

NSString *urlAddress = @”http://www.google.com”;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];

But if you want load html in the webview, this is wrong:

NSString *html = [NSString stringWithFormat:YOUTUBE_HTML,youtubeURLString];

and should be (assuming that YOUTUBE_HTML is well formatted):

NSString *html = [NSString stringWithFormat:@"%@%@",YOUTUBE_HTML,youtubeURLString];

Upvotes: 1

Related Questions