使用PageViewController上的下一个按钮

时间:2019-05-19 13:47:01

标签: ios swift

我有一个pageViewcontroller,它运行良好,可以左右滚动,但是现在我希望能够在下一页旁边添加按钮并使用button而不是在Viewcontroller上滑动。

下面是我从左向右滑动的基本代码

extension BaseVC: UIPageViewControllerDataSource, UIPageViewControllerDelegate {

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {

        var index = (viewController as! TableVC).pageIndex

        if (index == 0) || (index == NSNotFound) {
            return nil
        }

        index -= 1

        return viewControllerAtIndex(index: index)

    }

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {

        var index = (viewController as! TableVC).pageIndex

        if index == NSNotFound {
            return nil
        }

        index += 1

        if (index == self.pg.count) {
            return nil
        }

        return viewControllerAtIndex(index: index)
    }


    func presentationCount(for pageViewController: UIPageViewController) -> Int {
        return pg.count
    }

    func presentationIndex(for pageViewController: UIPageViewController) -> Int {
        return self.currentIndex
    }

    func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
        return 0
    }

    func viewControllerAtIndex(index: Int) -> TableVC? {
        if self.pg.count == 0 || index >= self.pg.count {
            return nil
        }

        let pageContentViewController = TableVC()
        pageContentViewController.pageM = pg
        pageContentViewController.pageIndex = index
        currentIndex = index
        pageContentViewController.tableView.reloadData()

        return pageContentViewController
    }
}

nextBtn和backBtn函数如下

@objc nextBtn(_ sender: Any) {

    }

    @objc backBtn(_ sender: Any) {

    }

任何帮助都会得到补偿

1 个答案:

答案 0 :(得分:1)

您需要在UIPageViewController子类中使用它

self.setViewControllers([someVC], direction: .forward, animated: true, completion: nil)