我一直在使用 XLPagerTabStrip 在我的 View Controller 的顶部有效地创建一个选项卡栏,其中显示多个 subview Controller (来源:https://github.com/xmartlabs/XLPagerTabStrip)
让我们调用这些 subview Controller A1、B1 和 C1。在 subview Controller 中是 TableView ,一旦点击 segue 到新的 View Controller (A2)。我希望能够从 A2 返回到显示 subview Controller 的第一个 View Controller 。我已经尝试向两个 subview Controller 添加一个导航栏并使用 navigationController?.popToRootViewControllerAnimated(true)
方法,但是当按下包含此代码的按钮时没有任何反应。我也尝试过在母 View Controller 中嵌入导航 Controller ,但这也不起作用(不确定这是否是因为 subview Controller A1、B1 和 C1 未连接到 Storyboard 中的母 View Controller )。
如有任何帮助,我们将不胜感激。
最佳答案
好的,所以我认为有几种方法可以解决这个问题。首先,答案取决于您使用的是哪种类型的 segue。如果你模态地使用现在,那么你需要做的就是输入
self.dismissViewControllerAnimated(true, completion: completion)
否则,请参阅下文以了解返回 A1ViewController 的方法。
第一个选项:
您可以将 Mother View Controller 嵌入到 UINavigationController 中。然后 Mother View Controller 将成为 UINavigationController 的 Root View Controller ,您将能够使用
navigationController?.popToRootViewControllerAnimated(true)
第二个选项:
一个放松的转场。这些 segue 非常适合倒退,可以分 3 步实现。
- 创建一个对象供用户选择返回(在您的情况下,这将是 A2 中的那个 UIButton)
在您要返回的 Controller 中创建一个展开方法。 (在您的情况下,该方法将在 Controller A1 中)
@IBAction func unwindToA1ViewController(segue: UIStoryboardSegue)
- 连接 UIStoryboard 中的方法。转到 A2 场景并控制拖动 A2ViewController 到 Exit,然后选择您在步骤 2 中创建的展开方法。(在 A2 ViewController 的最顶部)
请参阅下文以获得进一步的解释和精美的视觉效果! https://www.raywenderlich.com/113394/storyboards-tutorial-in-ios-9-part-2
希望这对您有所帮助!
关于ios - Swift:如何在使用 XLPagerTabStrip 中的 subview Controller 后返回到第一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37943774/