【发布时间】:2018-02-22 03:51:50
【问题描述】:
我正在尝试使用 unwind segue 从我的应用中注销。
这是我的视图层次结构:
MainVC->(show)->ConnectionVC->(show)->HomeTabBarVC->SettingsVC (4th tab of the HomeTabBarVC containing a tableview)
MainVC、ConnectionVC 和 HomeTabBarVC 位于三个不同的 Storyboard 中。
当按下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)
两者都没有工作......
有什么困难吗?
【问题讨论】:
-
你把
self.performSegue(...)这行代码放在哪里了?这应该可以正常工作,假设您正确创建并命名了 segue... -
在 tableView(_tableView: UITableView, didSelectRowAt indexPath: IndexPath)。我检查了对应于断开连接的行
-
OK - 所以...您将“展开”功能添加到
MainVC类代码...您从小“类”图标拖到@顶部的“退出”图标987654334@ 在 Interface Builder 中,并从弹出窗口中选择了你的展开功能......然后你在 Document Outline 中选择了那个 segue,并给了它“unwindToMainVC”标识符?你的 unwind 函数中有print()或其他东西,所以你知道它被调用了吗? -
顺便说一句...在您的项目中搜索您的展开函数名称的字符串。您是否碰巧在多个视图控制器中定义了它?
-
是的 DongMag 我做了所有的步骤,我什至可以看到打印。但现在我解决了我的问题,我会发布答案
标签: ios swift storyboard uitabbarcontroller unwind-segue