放松不会去正确的viewcontroller

问题描述:

我想使用unwind segue从我的应用程序注销。放松不会去正确的viewcontroller

这是我的看法层次:

MainVC->(show)->ConnectionVC->(show)->HomeTabBarVC->SettingsVC (4th tab of the HomeTabBarVC containing a tableview)

MainVC,ConnectionVC和HomeTabBarVC有三种不同的故事板。

当按下“断开”行SettingsVC时,我想放松到MainVC

我已经试图按照这样的:从教程被触发,但唯一

What are unwind segues and how do you use them?

Unwind segue and nav button items not triggering after tab bar controller added

unwindToThisViewController函数(我把MainVC),其发生的事情是回到HomeTabBarVC的第一个标签。

我试图以两种方式来执行在SettingsVC这个动作:

(self.tabBarController! as! HomeTabBarVC).performSegue(withIdentifier: "unwindToMainVC", sender: self) 

self.performSegue(withIdentifier: "unwindToMainVC", sender: self) 

他们都不是工作...

任何toughts?

+0

你把“self.performSegue(...)'代码行放在哪里?这应该工作得很好,假设你正确创建并命名了segue ... – DonMag

+0

在tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath)中。我检查行对应于断开连接 – steed

+0

行 - 所以... ...您将“退出”功能添加到“MainVC”类代码...您从小型“班级”图标拖动到顶部的“退出”图标'在界面生成器中使用HomeTabBarVC',并从弹出窗口中选择你的展开功能......然后你在文档大纲中选择了这个segue,并给它一个“unwindToMainVC”标识符?你有一个'print()'或者什么东西在你的unwind函数中,所以你知道它被调用了吗? – DonMag

你可以做到这一点,而不使用unwind segues。只需使用popToRootViewController

navigationController?.popToRootViewController(animated: true) 
+0

你好the4kman,谢谢你的快速回答! 虽然我没有使用UINavigationController .. – steed

我找到了解决办法:看,我有“的分离视图控制器呈现视图控制器被泄气”的警告后,我创建了一个代表我的HomeTabBarVC执行SEGUE和正常工作!谢谢大家的帮助!