【问题标题】:Pass website URL from Tableview to webview将网站 URL 从 Tableview 传递到 webview
【发布时间】:2014-06-24 19:13:53
【问题描述】:

您好,我创建了一个 NSMutablArray,并在 RootViewController 中向其中添加了 8 个对象。我在表格视图中显示数组。每当我单击具有特定名称的单元格时,我想将 URL 传递给当前属于另一个 DetailViewController 的 webview。

在该详细视图控制器中,必须显示相应的网页。


从评论中添加

我在 indexpath 的 didselect 行中编写了这段代码

CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0); 
UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame]; 
[webView setBackgroundColor:[UIColor whiteColor]]; 
NSString *urlAddress = @"h.com";; 
NSURL *url = [NSURL URLWithString:urlAddress]; 
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
[webView loadRequest:requestObj]; 
[self.view addSubview:webView]; 
[webView release]; 

我的数组名是listofitems,如何直接把我的数组调用到url地址中呢?

【问题讨论】:

    标签: uitableview ios4 uiwebview


    【解决方案1】:
    DetailsViewController *viewController = [[DetailsViewController alloc] 
      initWithNibName:@"DetailsViewController" bundle:nil];
    
    [viewController setUrl:actualUrl];
    

    actualUrl 是 rootViewController 中的值并在 detailViewController 中创建另一个变量 url

    【讨论】:

    • 我在 indexpath 的 didselect 行中写了这段代码 CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0); UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame]; [webView setBackgroundColor:[UIColor whiteColor]]; NSString *urlAddress = @"herbsforhealth.com"; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj]; [self.view addSubview:webView]; [webView 发布];我的数组名称是listofitems,所以我怎样才能将我的数组直接调用到url地址中。请帮助我
    • 在上面的代码中,我得到了每一行的静态网页。我想动态处理。所以我可以直接在 NSString *urladdress=@"http://%@",get listofitems; 行中调用我的数组吗?我可以这样做。如果是的话,调用我的数组的正确方法是什么
    • 你在哪里添加 webview。我的意思是你在哪里为 webView 编写代码
    • - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    • 不要忘记您可以编辑您的问题或答案,如果您在一行文本前放置 4 个空格,它会被格式化为代码(或选择您的代码并点击上方的 {} 按钮编辑区域,或在代码周围放置反引号`)。使其更具可读性和对未来寻找答案的人的帮助。
    猜你喜欢
    • 2018-06-07
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 2018-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多