0

我正在尝试在 UIWebView 中加载一个链接,该链接会随着用户在 UITableView 中选择不同的行而改变。目前我正在使用下面的代码,但它不能正常工作。

我基于 iOS 开发书中的示例代码。该代码可以在这里找到。示例代码源“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.    
}

有谁知道如何正确加载页面?

4

1 回答 1

1

好吧,如果你想在 UIWebview 中打开一个网站,你必须这样做:

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

但是如果你想在 webview 中加载 html,这是错误的:

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

并且应该是(假设 YOUTUBE_HTML 格式正确):

NSString *html = [NSString stringWithFormat:@"%@%@",YOUTUBE_HTML,youtubeURLString];
于 2012-05-17T09:31:51.873 回答