我有一个带有两个View Controllers的基于页面的应用程序。单击ViewController1中的按钮后,我试图从ViewController1移到ViewController2。

假设ViewController1的索引为0,ViewController2的索引为1。这就是我要在ViewController1.swift文件上执行的操作。

var viewCont = MyPageViewController()

viewCont.arrayViewControllers[1] (getting next ViewController from array declared in PageViewController file)

scrollToViewController(viewCont.arrayViewControllers[1], direction: .Forward)



func scrollToViewController(viewController: UIViewController,
                                    direction: UIPageViewControllerNavigationDirection = .Forward) {
           viewCont.setViewControllers([viewController],
                               direction: direction,
                               animated: false,
                               completion: { (finished) -> Void in
            })

            viewCont.tutorialDelegate?.tutorialPageViewController(viewCont,
didUpdatePageIndex: 1)
        }


myPageViewController的代码段

protocol TutorialPageViewControllerDelegate: class {

    /**
     Called when the current index is updated.

     - parameter myPageViewController: the MyPageViewController instance
     - parameter index: the index of the currently visible page.
     */
    func tutorialPageViewController(tutorialPageViewController: TutorialPageViewController,
        didUpdatePageIndex index: Int)
 }

最佳答案

有一个很好的教程,向您展示了如何执行此操作。下一个按钮将页面视图切换到下一页。

https://github.com/jeffaburt/UIPageViewController-Post

关于ios - 如何在基于页面的应用程序(PageViewController)中单击按钮时从ViewController1移至ViewController2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37994167/

10-15 14:12