Xcode 6 - 将segue推送到同一个视图控制器 [英] Xcode 6 - Push segue to same view controller

查看:68
本文介绍了Xcode 6 - 将segue推送到同一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表视图控制器,并且点击一个单元格可以根据单元格中的数据类型触发许多不同类型的推送段之一。在tableView:didSelectRowAtIndexPath中确定正确segue的标识符:然后使用self.performSegueWithIdentifier触发segue:

I have a table view controller and tapping on a cell can trigger one of many different types of push segues based on the type of data in the cell. The identifier of the correct segue is determined in tableView:didSelectRowAtIndexPath: and then the segue is triggered with self.performSegueWithIdentifier:

对于其中一个segue,我想要将同一视图控制器的另一个实例推送到导航堆栈。这是否可以在不必将相同类型的新视图控制器对象拖到故事板上?到目前为止,如果我从表格单元格Ctrl +拖动到视图控制器,我只能将segue连接到同一个视图控制器。这不是我想要的。

For one of those segues, I'd like to push another instance of the same view controller on to the navigation stack. Is this possible without having to drag a new view controller object of the same type onto the storyboard? So far, I have only been able to wire up a segue to the same view controller if I Ctrl + Drag from the table cell to the view controller. This is not what I want.

推荐答案

正如所建议的那样,我认为segue不会起作用。相反,您可以以编程方式推送同一视图控制器的新实例,这与执行segue具有相同的效果。区别在于不会调用诸如prepareForSegue之类的segue委托方法。

As suggested, I don't think a segue will work. Instead you can push a new instance of the same view controller programmatically, which will have the same effect as performing the segue. The difference is that segue delegate methods like prepareForSegue won't be called.

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyViewController *vc = [[MyViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
} 

这篇关于Xcode 6 - 将segue推送到同一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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