简体   繁体   English

我是故事板中的5个控制器,我如何以编程方式弹回到“官方初始控制器”?

[英]I am 5 Controllers deep into a Storyboard, how do I programmatically pop back to the Official Initial Controller?

I am 5 Controllers deep into a Storyboard, how do I programmatically and easily pop back to the Official Initial Controller? 我是情节提要中的5个控制器,我如何以编程方式轻松地弹出官方初始控制器?

Is there some one liner for this? 有一些衬板吗? What is the most elegant and simple solution? 什么是最优雅,最简单的解决方案?

1 - On your root VC, create an unwind method: something like: 1-在根VC上,创建一个展开方法:

- (IBAction)unwindToRoot:(UIStoryboardSegue*);

Then wire it up to "exit" in your storyboard. 然后将其连接到情节提要中的“退出”。 This is an unwind segue. 这是一场轻松的比赛。

or 2 - In your fifth VC, pop back manually: 或2-在第五个VC中,手动弹出:

[self.navigationController popToRootViewControllerAnimated:YES]

Indeed, there is a one-liner: 确实,有一条线:

[self.navigationController popToViewController:(UIViewController *)];

Of course you would replace (UIViewController *) with the view controller at the beginning of the nav stack. 当然,您可以在导航堆栈的开头将(UIViewController *)替换为视图控制器。

暂无
暂无

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

相关问题 如何以编程方式在包含WKInterfaceController的情节提要中设置初始控制器? - How can I set the initial controller on storyboard contains WKInterfaceController programmatically? 如何在不在同一个故事板上的视图控制器之间以编程方式切换? - How can I switch programmatically between view controllers that are not on the same storyboard? 如何从未连接到其他视图控制器的视图控制器传输回视图控制器? - How do I transfer back to a view controller from a view controller that is not connected to other view controllers? 在故事板中,如何制作用于多个控制器的自定义单元格? - In a storyboard, how do I make a custom cell for use with multiple controllers? 如何使用给定的根ViewController和初始ViewController实例化情节提要? - How do I instantiate a storyboard with a given root viewcontroller and initial viewcontroller? 我希望我的故事板的初始视图控制器是当前的控制器 - I expect the initial view controller of my storyboard to be the current controller 为什么我无法在AppDelegate中以编程方式更改初始视图控制器? - Why am I unable to change my initial view controller programmatically in my AppDelegate? 如果是在Storyboard中创建的,如何以编程方式更改UIToolbar按钮? - How do I change UIToolbar buttons programmatically if created in Storyboard? 如何将故事板中的UITextField替换为以编程方式? - How do I replace a UITextField from storyboard to programmatically? 如何检查视图控制器是否为初始视图控制器? (SWIFT 3) - How do I check if view controller is initial view controller? (SWIFT 3)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM