[英]Unwind not going to the right viewcontroller
I am trying to use an unwind segue to logout from my app. 我正在尝试使用放松的状态从我的应用程序注销。
Here is my view hierarchy: 这是我的视图层次结构:
MainVC->(show)->ConnectionVC->(show)->HomeTabBarVC->SettingsVC (4th tab of the HomeTabBarVC containing a tableview)
MainVC, ConnectionVC and HomeTabBarVC are in three different Storyboards. MainVC,ConnectionVC和HomeTabBarVC位于三个不同的Storyboard中。
When pressing the "Disconnect" row of SettingsVC
, I want to unwind to MainVC
. 当按下
SettingsVC
的“ Disconnect”行时,我想展开到MainVC
。
I already tried to follow this: 我已经尝试遵循此:
What are unwind segues and how do you use them? 什么是放松的搜寻,如何使用?
and 和
Unwind segue and nav button items not triggering after tab bar controller added 添加选项卡栏控制器后,不触发取消搜索和导航按钮项
The unwindToThisViewController
function (which I put in MainVC
) from the tutorial is triggered but the only thing that happens is going back to the first tab of HomeTabBarVC
. 触发了本教程中的
unwindToThisViewController
函数(我在MainVC
放入了该MainVC
),但是唯一发生的事情是回到HomeTabBarVC
的第一个选项卡。
I tried to execute this action in SettingsVC
in two ways: 我试图通过两种方式在
SettingsVC
中执行此操作:
(self.tabBarController! as! HomeTabBarVC).performSegue(withIdentifier: "unwindToMainVC", sender: self)
and 和
self.performSegue(withIdentifier: "unwindToMainVC", sender: self)
Neither are working... 都没有工作...
Any toughts? 有困难吗?
You can do this without using unwind segues. 您可以执行此操作,而无需使用放松进度。 Just use
popToRootViewController
: 只需使用
popToRootViewController
:
navigationController?.popToRootViewController(animated: true)
I found a solution : after seeing that I had the "Presenting view controllers on detached view controllers is discouraged " warning, I created a Delegate to execute the segue in my HomeTabBarVC and it works fine! 我找到了一个解决方案:看到“不鼓励在分离的视图控制器上提供视图控制器”警告后,我创建了一个Delegate来在HomeTabBarVC中执行segue,并且工作正常! Thanks everyone for your help!!
谢谢大家的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.