Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableViewController中的静态单元格在同一nib上打开不同的URL_Iphone_Ios_Xcode_Uitableview_Uiwebview - Fatal编程技术网

Iphone UITableViewController中的静态单元格在同一nib上打开不同的URL

Iphone UITableViewController中的静态单元格在同一nib上打开不同的URL,iphone,ios,xcode,uitableview,uiwebview,Iphone,Ios,Xcode,Uitableview,Uiwebview,我是UITableViewController的新手,我想制作一个静态单元格UITableViewController,每个静态单元格打开相同的nib文件,但UIWebView的URL将不同。e、 g.第1行将在google.com和yahoo.com中打开第2行。我可以知道我怎么做吗 谢谢您需要实现tableview委托方法,tableview:didSelectRowAtIndexPath:,这将允许您询问tableview选择了哪个单元格,然后采取适当的操作。例如: - (void)tab

我是UITableViewController的新手,我想制作一个静态单元格UITableViewController,每个静态单元格打开相同的nib文件,但UIWebView的URL将不同。e、 g.第1行将在google.com和yahoo.com中打开第2行。我可以知道我怎么做吗


谢谢

您需要实现tableview委托方法,
tableview:didSelectRowAtIndexPath:
,这将允许您询问tableview选择了哪个单元格,然后采取适当的操作。例如:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if ([cell.textLabel.text isEqualToString:@"google"]) {
        // open google
    } else if ([cell.textLabel.text isEqualToString:@"yahoo"]) {
        // open yahoo
    }
}
编辑以回答评论中提出的问题

您没有说明这一点,但通过阅读您的问题,我猜您正在使用单独的nib文件,并且希望在屏幕上推送另一个视图控制器,当用户选择一个静态单元格时,该控制器控制web视图。执行此操作的步骤包括:

  • 创建新的VC
  • 为公共属性指定要加载的URL
  • 在屏幕上按下VC
  • 在代码中,类似于:

     WebViewController webVC = [[WebViewController alloc] initWithNibName:@"your nib name" bundle:[NSBundle mainBundle]];
     webVC.url = // some NSURL object, or maybe just a string that has the URL - that's up to you
     [self.navigationController pushViewController:webVC animated:YES]
    

    但是如何将其连接到下一个nib UIwebView?我需要在下一个nib中添加什么代码?谢谢