编程表视图分段向下钻取



我目前正在尝试将我的应用程序转换为情节提要。我的数据当前存储在plist文件中,使用当前didSelectRowAtIndexPath:方法中的以下代码,我可以非常容易地深入查看表视图:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
NSArray *children = [dictionary objectForKey:@"Children"];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([children count] == 0)
{
    NSString *tempString1 = [dictionary valueForKeyPath:@"Movie"];
    NSString *tempString2 = [dictionary valueForKeyPath:@"Text"];
    NSString *tempString3 = [dictionary valueForKeyPath:@"Diagram"];
    DetailsVC *dvc = [[DetailsVC alloc] initWithNibName:@"DetailsVC" bundle:nil];
    dvc.movie = tempString1;
    dvc.pdfdesc = tempString2;
    dvc.pdfDiagram = tempString3;
    dvc.navigationItem.title = [dictionary valueForKeyPath:@"Title"];
  [self.navigationController pushViewController:dvc animated:YES];
}
else
{
    LevelsVC *lvc = [[LevelsVC alloc] initWithNibName:@"LevelsVC" bundle:[NSBundle mainBundle]];
    lvc.currentLevel += 1;
    lvc.navigationItem.title = [dictionary valueForKeyPath:@"Title"];
    [self.navigationController pushViewController:lvc animated:YES];
    lvc.tableDataSource = children;
    }

我的问题是:我究竟该如何将此方法转换为与Segues和Storyboards一起使用?我可以很容易地为detailViews创建一个segue,网上有一百万个关于它的教程,但我根本不知道如何深入查看表视图中的数据。

如有任何帮助或示例代码,我们将不胜感激!

您可以使用-performSegueWithIdentifier:sender:以编程方式从一个视图控制器转换到另一个。只需将配置dvc的代码移动到您的-prepareForSegue:sender:实现中即可。

另一种选择是将序列图像板中的片段从表中的一个单元格连接到下一个视图控制器。这将导致一旦选择行就触发segue,从而避免您必须以编程方式启动segue。在这种情况下,只需实现-prepareForSegue:sender:即可在segue的目标视图控制器中设置任何必要的数据。sender参数将是所点击的表格单元格,您可以使用它来查找所选行。

最新更新