Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.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 在情节提要中推送视图_Ios_Ios5_Storyboard - Fatal编程技术网

Ios 在情节提要中推送视图

Ios 在情节提要中推送视图,ios,ios5,storyboard,Ios,Ios5,Storyboard,我正在尝试使用表视图和导航控制器。这是我在使用NIB文件时会用到的代码。如果我使用NIB文件,这段代码可以正常工作,但我决定试试情节提要- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (_webViewController == nil) { self.webViewController = [[[WebViewController al

我正在尝试使用表视图和导航控制器。这是我在使用NIB文件时会用到的代码。如果我使用NIB文件,这段代码可以正常工作,但我决定试试情节提要-

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if (_webViewController == nil) {
    self.webViewController = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
_webViewController.entry = entry;
[self.navigationController pushViewController:_webViewController animated:YES];
}
我已经在故事板中创建了另一个场景,并在那里设置了一切。当用户单击此表视图中的单元格时,他们将被带到该场景。这是我写的代码,但它是不正确的,我绝望地卡住了:(-


答案-答案2和答案3都是正确的

您可能会发现这个由两部分组成的优秀教程很有帮助


您可能会发现本精彩的两部分教程非常有用


如果您的表视图已经嵌入到导航控制器中(从您的第一个代码片段看,是这样的),那么您的segue的目标视图控制器将是WebViewController,而不是导航控制器

因此,您可以让prepareForSegue方法直接将项目传递到:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"articleView"])
    {
        WebViewController *controller = (WebViewController *)segue.destinationViewController;
        RSSEntry *entry = [_allEntries objectAtIndex:[self.tableView indexPathForSelectedRow].row];
        controller.entry = entry;
    }
}

如果您的表视图已经嵌入到导航控制器中(从您的第一个代码段看是这样的),则segue的目标视图控制器将是WebViewController,而不是导航控制器

因此,您可以让prepareForSegue方法直接将项目传递到:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"articleView"])
    {
        WebViewController *controller = (WebViewController *)segue.destinationViewController;
        RSSEntry *entry = [_allEntries objectAtIndex:[self.tableView indexPathForSelectedRow].row];
        controller.entry = entry;
    }
}

两天前,我遇到了一个非常类似的问题,用户连续选择了披露附件,并希望调用segue。对我有效的方法是:

  • 在情节提要中,从整个tableView控制器(而不是单元格)到下一个viewController创建分段“articleView”
  • 将以下方法添加到tableViewController:
  • 就为了你,我还使用tableView:didSelectRowatineXpath:进行了测试,它可以正常工作

    享受


    Damien

    两天前,我遇到了一个非常类似的问题,用户连续选择了披露附件,并希望调用一个segue。对我有效的是:

  • 在情节提要中,从整个tableView控制器(而不是单元格)到下一个viewController创建分段“articleView”
  • 将以下方法添加到tableViewController:
  • 就为了你,我还使用tableView:didSelectRowatineXpath:进行了测试,它可以正常工作

    享受

    达米恩

    - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {  
        [self performSegueWithIdentifier:@"articleView" sender:[self.tableView cellForRowAtIndexPath:indexPath]];
    }