【问题标题】:UIPageViewControllerDataSource - segueForUnwindingToViewController not being calledUIPageViewControllerDataSource - segueForUnwindingToViewController 没有被调用
【发布时间】:2015-07-15 04:21:23
【问题描述】:

我有一个 UIViewController,它被设置为一个名为 MainPVC.swift 的 UIPageViewControllerDataSource。这是我在故事板上的切入点。在其中,我正在实例化另一个名为 TrackerVC 的 UIViewController,它设置在我的 Storyboard 中 - 但没有通过 segue 连接到 MainPVC。

实例化 TrackerVC:

func viewControllerAtIndex(index: Int) -> TrackerVC {
    let childViewController = self.storyboard?.instantiateViewControllerWithIdentifier("trackerVC") as TrackerVC
    childViewController.screenIndex = index
    return childViewController
}

我有另一个名为 NotesVC 的 UIViewController。当我按下 TrackerVC 上的按钮时,我使用自定义 UIStoryBoardSegue 来显示 NotesVC。在 NotesVC 上,我有另一个按钮,我想通过 Unwind 使用另一个自定义 UIStoryboardSegue 返回到 TrackerVC。

在 NotesVC 中点击了取消按钮:

@IBAction func cancelButtonTapped(sender: AnyObject) {
        self.performSegueWithIdentifier("unwindFromNotesSegue", sender: self)
    }

现在我的问题 -

当我按下 TrackerVC 上的按钮时,自定义 UIStoryboardSegue 运行良好,并按预期显示 NotesVC。但是,当我点击 NotesVC 上的按钮时,自定义 UIStoryboardSegue 将被忽略,并且正在使用向下滑动视图的通用 segue。

我已将问题追溯到 TrackerVC 中未调用 segueForUnwindingToViewController。我在 Storyboard 中正确设置了所有连接以及所有必需的方法(unwind 使用的方法)。

我还尝试创建第三个 UIViewController 并使用自定义 UIStoryboardSegues 和 Unwind 显示它,并从 NotesVC 调用它,一切正常。如预期的那样,在 NotesVC 上调用 segueForUnwindingToViewController。

感谢您的帮助!

【问题讨论】:

    标签: ios swift uistoryboardsegue


    【解决方案1】:

    你有NavigationController 附件吗?您可能需要继承 NavigationController 并在其中添加 segueForUnwindingToViewController。它解决了我遇到的类似问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-15
      • 1970-01-01
      • 1970-01-01
      • 2018-11-25
      • 2019-03-31
      • 2012-12-16
      • 2015-03-28
      • 2012-12-04
      相关资源
      最近更新 更多