使用故事板非常简单。你只需将动作拖到“退出”。但是如何从代码中调用它呢?


当前回答

我使用[self disdisviewcontrolleranimated: YES completion: nil];它会将你返回到调用ViewController。

其他回答

Vishal Chaudhry的回答对我很有用。我还会添加,为了手动触发seque使用:

[self performSegueWithIdentifier:@"mySegueName" sender:self];

在ViewController中,你还必须在故事板中ViewController的场景下选择unwind segue,并在RHS的属性视图中确保标识符字段包含你在代码中引用的名称(在上面的例子中是“mySegueName”)。

如果省略此步骤,上面的行将抛出一个异常,表示序列名未知。

Bradleygriffith的回答很好。为了简化,我采取了第10步,并做了一个截图。这是Xcode 6的截图。

从橙色图标控制拖动到红色Exit图标,在视图中创建一个没有任何操作/按钮的展开。

然后在侧边栏中选择unwind segue:

设置Segue标识符字符串:

从代码中访问该标识符:

[self performSegueWithIdentifier:@"unwindIdentifier" sender:self];

创建一个手动segue (ctrl-drag from File 's Owner to Exit), 选择它在左侧控制器菜单下面绿色退出按钮。

插入要unwind的Segue名称。

然后,- (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender.与您的续集识别。

我使用[self disdisviewcontrolleranimated: YES completion: nil];它会将你返回到调用ViewController。

向后兼容的解决方案,将工作于ios6之前的版本,为那些感兴趣:

- (void)unwindToViewControllerOfClass:(Class)vcClass animated:(BOOL)animated {

    for (int i=self.navigationController.viewControllers.count - 1; i >= 0; i--) {
        UIViewController *vc = [self.navigationController.viewControllers objectAtIndex:i];
        if ([vc isKindOfClass:vcClass]) {
            [self.navigationController popToViewController:vc animated:animated];
            return;
        }
    }
}