【问题标题】:two webPage on single UIWebView单个 UIWebView 上的两个网页
【发布时间】:2012-02-05 05:30:20
【问题描述】:

我正在制作一个 iPad 应用程序,

我想在单个 UIWebView 上一个接一个地加载 2 个网页,

第一个网页应该在我加载我的应用程序时出现,第二个网页应该在点击 tableView 的单元格时出现,

所以,在我的 didLoad 方法中,我正在写这个(第一个网页),

NSString *urlAddress = @”http://www.google.com”;

//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];

//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//Load the request in the UIWebView.
[webView loadRequest:requestObj];

效果很好..

但是在同一个 webview 的同一页面上单击 tableView 的单元格我想加载另一个页面,(第二个网页)

我编写了相同的代码,当我单击 tableView 图形的单元格时没有显示,

我需要清除网页或重新加载网页吗?

帮帮我,提前谢谢!!

【问题讨论】:

  • 您为加载第二个网页视图编写的代码是什么?
  • 你确定加载第二个网页视图的代码正在运行吗?您可能希望通过日志记录进行验证。响应未运行事件的代码是一个非常常见的错误。
  • NSString *urlAddress1 = @” yahoo.com”; //创建一个URL对象。 NSURL *url1 = [NSURL URLWithString:urlAddress1]; //URL 请求对象 NSURLRequest *requestObj1 = [NSURLRequest requestWithURL:url1]; //在UIWebView中加载请求。 [webView loadRequest:requestObj1];

标签: iphone ios ipad uitableview uiwebview


【解决方案1】:

调用这个方法,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
  NSString *urlAddress = @”http://www.google.com”;

//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];

//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//Load the request in the UIWebView.
[webView loadRequest:requestObj];

}

【讨论】:

    【解决方案2】:

    我从您的评论中看到您对第二个请求使用了错误的 URL 格式:

    NSString *urlAddress1 = @”yahoo.com”; //Create a URL object.
    NSURL *url1 = [NSURL URLWithString:urlAddress1]; //URL Requst Object 
    NSURLRequest *requestObj1 = [NSURLRequest requestWithURL:url1]; //Load the request in the 
    UIWebView. [webView loadRequest:requestObj1];
    

    网址必须以

    开头
    http://  
    

    否则将无法正常工作。

    【讨论】:

    • 我的网址里也有http://,我忘了写在这里,还有什么错误吗?
    猜你喜欢
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-19
    • 1970-01-01
    相关资源
    最近更新 更多