Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.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
Ios 如何为表上的不同URL组织detail controller webview?_Ios_Objective C_Uitableview_Uiwebview - Fatal编程技术网

Ios 如何为表上的不同URL组织detail controller webview?

Ios 如何为表上的不同URL组织detail controller webview?,ios,objective-c,uitableview,uiwebview,Ios,Objective C,Uitableview,Uiwebview,我有一个静态表视图,其中有几十个静态单元格和组。我正在为iPad使用Master Detail应用程序模板。在详细视图控制器中我有一个网络视图。我正在尝试这样做,当用户选择一个单元格时,它将使用以下代码将不同的URL加载到WebView: [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mywebsite.com"]]]; 所以我的问题是 有没有一种简单的方法可以让

我有一个静态表视图,其中有几十个静态单元格和组。我正在为iPad使用
Master Detail应用程序
模板。在
详细视图控制器中
我有一个
网络视图
。我正在尝试这样做,当用户选择一个单元格时,它将使用以下代码将不同的URL加载到
WebView

[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mywebsite.com"]]];
所以我的问题是

有没有一种简单的方法可以让
WebView
在每个唯一的单元格中加载不同的URL?表中每个单元格的唯一区别是标题,我认为每个单元格指向不同的视图(这需要80多个控制器)是不实际的


提前感谢。

当然,您只需要让数据源包含要显示的标题和要传递到详细信息视图的URL。您可以有一个字典数组,其中一个键用于标题,另一个键用于URL

编辑后:

下面是一个使用表的示例,该表有3个部分,分别有1行、3行和2行。数组的结构与该表结构相匹配——三个子数组包含1、3和2个元素

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *first = @[@"http://www.mywebsite.com"];
    NSArray *second = @[@"http://www.anotherwebsite.com",@"http://www.somewebsite.com",@"http://www.randomwebsite.com"];
    NSArray *third = @[@"http://www.apple.com",@"http://www.google.com"];
    self.theData = @[first,second,third];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *urlString = self.theData[indexPath.section][indexPath.row];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}

我对这方面还比较陌生,你能更详细地讲一下并给我一个代码示例吗?@Collin,我不知道该给你看什么,因为我不知道你现在在做什么。您现在是如何填充单元格的?它们都是我通过拖放对象创建的静态单元格。@Collin,您需要实现tableView:DidSelectRowatineXpath:。在不知道表结构(有多少行和节)的情况下,很难提供代码示例,但是您可以通过上述方法获得选定单元格的indexPath,并使用该indexPath从创建的数组中选择URL。该数组可以是一个数组数组,您可以使用indexPath.section选择一个子数组,使用indexPath.row选择该子数组中的元素。