简体   繁体   English

从UITabviewController导航回到情节提要中的ViewController

[英]Navigate back from UITabviewController to ViewController in storyboard

My hierarchy 我的阶层

 UINavigationController -> UIViewController 
 -> UITabViewController 
     -> ViewController1                                                      
     -> ViewController2
     -> ViewController3

I want to navigate back from 我想从导航

ViewController1 -> UIViewController.

Anyone know please solve this issues. 任何人都知道,请解决此问题。

"Unwind" is your answer. “放松”是您的答案。

在此处输入图片说明

Create an IBAction method to unwind segue. 创建一个IBAction方法以解除锁定。 Define this method in a controller in which you want to unwind (Controller from you want to jump back to main controller). 在要展开的控制器中定义此方法(要从中跳回主控制器的控制器)。

- (IBAction) prepareForUnwind:(UIStoryboardSegue *)segue {
}

Now connect back button (in this case "Home" button) with this method in Storyboard. 现在,使用情节提要中的此方法连接后退按钮(在本例中为“主页”按钮)。 To connect unwind action -> Ctrl-drag to "Exit" outlet button of your controller. 要连接展开动作-> Ctrl拖动到控制器的“退出”出口按钮。

在此处输入图片说明

Note: If you are using Xcode version less than 6.0 than "Exit" outlet is located at bottom of your view controller. 注意:如果您使用的Xcode版本低于6.0,则“ Exit”出口位于视图控制器的底部。

在此处输入图片说明

This will navigate back to your root navigation controller. 这将导航回到您的根导航控制器。 That is UIViewController. 那就是UIViewController。

For further separation you can give an identifier to unwind segue and make different actions for exit to last controller. 为了进一步分离,您可以指定一个标识符以解除顺序并做出不同的动作以退出到最后一个控制器。

Select identifier from left list and give an identifier in Attributes inspector. 从左侧列表中选择标识符,然后在“属性”检查器中提供一个标识符。

在此处输入图片说明在此处输入图片说明

Key points: 关键点:

  1. Write unwind method in a controller which will be exited. 在将要退出的控制器中写入展开方法。
  2. Connection to "Exit" delegate will only works after you define unwind method. 只有定义了展开方法后,才能连接到“退出”委托。
  3. Ctrl+Drag from a control to the Exit symbol to select the unwind segue you want this control to perform 按住Ctrl键并从控件中拖动到“退出”符号,以选择要让此控件执行的展开序列
  4. Unwind segues appear below the Exit symbol for each connection made 每次连接时,“退出”标志都会出现在“退出”符号下方
  5. You can give those unwind segues an identifier to have different activities performed. 您可以为那些放松的搜寻者指定一个标识符,以执行不同的活动。

You can use 您可以使用

    [navigationController popToViewController:<#(UIViewController *)#> animated:<#(BOOL)#>];

just provide the instance of the viewController you want to pop to and set animated property to YES if u want pop with animation and NO if not. 只需提供要弹出到的viewController的实例,然后将动画属性设置为YES(如果您想弹出动画),否则设置为NO。

Here the controller UIViewController is the rootViewController of UINavigationController . 这里的控制器UIViewControllerUINavigationController的rootViewController。 So you just need to pop to the rootViewController from the ViewController1 所以你只需要从ViewController1弹出到rootViewController

[self.navigationController popToRootViewControllerAnimated:YES];

You can done by this: 您可以这样做:

ViewController *loginVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[self.navigationController popToViewController: loginVC animated:YES]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM