故事板针对不同的表格视图单元转换到不同的视图控制器

发布于 2025-01-06 23:07:07 字数 972 浏览 1 评论 0原文

我已经找到了有关创建从一个表视图到另一个视图的过渡的教程。单击单元格时的转换将转到相同的目标视图控制器。我想知道如何为表视图中的每个单元格转换到不同的视图控制器。我还能用情节提要来做到这一点吗?如果是这样,怎么办?如果没有,您可以建议什么替代方案?

故事板已从表格视图连接到详细视图。但这就是我想要完成的:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  if ([[segue identifier] isEqualToString:@"mytransition"]) {

    NSInteger sectionId = [[self.tableView indexPathForSelectedRow] section];
    if (sectionId == 0) {
        NSLog(@"try to change the destination view controller");
        //I don't know if this is possible?!
    } else {
        NSLog(@"Proceed with the original destination view controller");
        //this is ok
    }
  }
}

编辑:我找到了解决方案!您可以在这里查看:http://forums.macrumors.com/showthread.php?t =1274743

总之,该解决方案涉及对任何感兴趣的人使用prepareForSegue 和didSelectRowAtIndexPath 的组合。不要将每个单元格链接到另一个视图,而是创建从控制器到每个所需视图控制器的另一个 Segue。然后检查segue 标识符。

-仁

I have been able to find tutorials on creating the transition from one tableview to another view. The transition when you click on a cell is to the same destination view controller. I was wondering how I could transition to different view controllers for each of the cells in the tableview. Can I still do this with storyboard? If so, how? If not, what alternatives can you suggest?

The storyboard has been hooked up from the tableview to a detailed view. But this is what I would like to accomplish:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  if ([[segue identifier] isEqualToString:@"mytransition"]) {

    NSInteger sectionId = [[self.tableView indexPathForSelectedRow] section];
    if (sectionId == 0) {
        NSLog(@"try to change the destination view controller");
        //I don't know if this is possible?!
    } else {
        NSLog(@"Proceed with the original destination view controller");
        //this is ok
    }
  }
}

EDIT: I found the solution! You can view it here: http://forums.macrumors.com/showthread.php?t=1274743

In summary, the solution involved using a combination of the prepareForSegue and didSelectRowAtIndexPath for anyone who's interested. Instead of linking each cell to another view, create another segue from the controller to each of the desired view controllers. Then check the segue identifier.

-Jen

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趴在窗边数星星i 2025-01-13 23:07:07

珍是对的。 Jen 链接中的解决方案确实有效。

  • 创建从表中的原型单元到目标视图控制器的segue
  • 设置segue的标识符。
  • 修改 didSelectRowAtIndexPath 以获取所选单元格的行号,并使用该单元格的 segue 标识符调用 performSegueWithIdentifier

Jen's right. The solution from Jen's link does work.

  • Create the segue from the prototype cell in the table to the destination view controller.
  • Set the identifier of the segue.
  • Modify didSelectRowAtIndexPath to get the row number of the selected cell, and call performSegueWithIdentifier with the segue identifier for that cell.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文