unwind segue vs. popViewControllerAnimated

随声附和 提交于 2019-12-20 04:06:22

问题


I have a mapview that is connected to several viewControllers.

I needed to implement an 'unwind' from another button (as opposed to just the back button), so I used:

self.navigationController?.popViewControllerAnimated(true)

My question is: as the above works, should I even bother trying to implement unwind in code using prepareForUnwind and canPerformUnwindSegueAction in the parent view controller + ctrl-drag from the viewController to exit in Storyboard? If so, why?


回答1:


Basically if you are just dimissing a presented UIViewController or popping a UIViewController from the navigation stack,you don't need to use unwind segues although it does the same for you.

But think of a case where there are UINavigationControllers A,B,C and then a RootViewController R

Then think of a condition

 (Present) R -> A
 (Push) AR -> XVController
 (Push)XVController -> B
 (Present)BR-> YVContoller
...and so on..

Now if you want to go back to YVController to your project RootViewController where you just started up.There is no way as popToRootViewController pops to the navigation stack of the B UINavigationController.Now what you do..Either use delegate or change window RootViewController which is not a good idea.

So you need to use unwind segue to overcome this.. A sample project to demonstrate the power of using it..



来源:https://stackoverflow.com/questions/35300192/unwind-segue-vs-popviewcontrolleranimated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!