编程tableview segue向下钻取 [英] Programming tableviews segue drill down

查看:87
本文介绍了编程tableview segue向下钻取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试将我的应用转换为情节提要.我的数据当前存储在一个plist文件中,我可以在当前的didSelectRowAtIndexPath:方法中使用以下代码轻松地浏览我的表视图:

I am currently trying to convert my apps to Storyboards. My data is currently stored in a plist file and I drill down through my tableviews very easily using the following code in my current didSelectRowAtIndexPath: method:

-(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和Storyboard?我可以轻松地为detailViews创建一个序列,网上有100万个教程,但是我根本无法弄清楚如何在表视图中向下钻取数据.

My question is: How on earth do I convert this method for use with Segues and Storyboards? I can easily create a segue for detailViews, and there are a million tutorials for that on the net, but i simply cannot figure out how to drill down through the data in my tableview.

任何帮助或示例代码将不胜感激!

Any help or sample code would be greatly appreciated!

推荐答案

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

You can use -performSegueWithIdentifier:sender: to transition from one view controller to another programmatically. Just move the code that configures dvc to your -prepareForSegue:sender: implementation.

另一个选择是将情节提要中的segue从表中的单元格连接到下一个视图控制器.选中该行后,将立即触发segue,从而使您完全不必以编程方式启动segue.在这种情况下,只需实现-prepareForSegue:sender:即可在segue的目标视图控制器中设置任何必要的数据. sender参数将是被点击的表格单元格,您可以使用它来查找选定的行.

Another option is to connect your segue in the storyboard from a cell in the table to the next view controller. That will cause the segue to be triggered as soon as the row is selected, which prevents you from having to start the segue programmatically at all. In that case, you just implement -prepareForSegue:sender: to set any necessary data in the segue's destination view controller. The sender parameter will be the table cell that was tapped, and you can use that to find the selected row.

这篇关于编程tableview segue向下钻取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆