如何在故事板中移回根视图控制器? [英] How to move back to the root view controller in storyboard?

查看:128
本文介绍了如何在故事板中移回根视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的事情似乎很简单,但我在网上找不到任何答案。我有登录屏幕作为根视图控制器,然后是标签栏控制器,在每个选项卡中我都有一个导航控制器。

What I want to do seems pretty simple, but I can't find any answers on the web. I have the login screen as the root view controller and then tab bar controller and in every tab I have a navigation controller.

我使用了故事板,层次结构如下所述,

I have used storyboard and the hierarchy is described below,

Root VC
    |
     --- tabbar controller
          |
           ---Navigation Controller
                |
                 --- VC1

要求是从VC1导航回根视图控制器。我们怎样才能做到这一点?

Requirement is to navigate back to the root view controller from VC1. How can we achieve this?

推荐答案

我使用Unwind Segues解决了问题。

I got the resolution to the issues using the "Unwind Segues".

步骤1)您需要的最小值是为目标视图创建视图控制器的子类(也就是先前在导航中弹出的视图,并且您想要展开它)并向其添加这样的方法(方法名称可以是您想要的任何名称,但它应该是唯一的,因为整个应用程序中的所有展开segue都列在一起):

Step 1) The bare minimum you need is to subclass the view controller for your destination view (aka, a view that has popped up previously in navigation and you want to unwind to it) and add a method like this to it (the method name can be anything you want, but it should be unique because all unwind segues in your entire app are listed together):

- (IBAction)unwindToViewControllerNameHere:(UIStoryboardSegue *)segue {
//nothing goes here
}

步骤2)现在,在您的源视图(也就是您想要放松的视图)中,您只需将按钮中的segue或者向下拖动到底部的绿色EXIT图标您的源视图。现在应该有一个连接到 - unwindToViewControllerNameHere的选项

Step 2) Now, in your source view (aka, the view that you want to unwind from) you simply drag a segue from your button or whatever down to the little green "EXIT" icon at the bottom of your source view. There should now be an option to connect to "- unwindToViewControllerNameHere"

就是这样,你的segue将在点击你的按钮时放松。我们可以移动到我们想要的任何视图控制器,其余的视图控制器将被释放。

That's it, your segue will unwind when your button is tapped. And we can move to any view controller we want and rest of the view controllers will be released.

这篇关于如何在故事板中移回根视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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