选择UIPageViewController

选择UIPageViewController

我试图在用户登录后向我的应用程序添加一个教程部分。当应用程序加载后,他们将首先进入登录屏幕并输入其凭据。验证之后,我想选择UIPageViewController并向他们展示两页有关如何使用该应用程序的说明。但是,我所有的尝试都导致黑屏。这是我目前的尝试:

import UIKit

class TutorialPageViewController: UIPageViewController {

    var pages: [UIViewController] = []

    override func viewDidLoad()
    {
        super.viewDidLoad()
        self.dataSource = self
        self.delegate   = self
        print("LOADING")
        let firstView = storyboard?.instantiateViewController(withIdentifier: "TutorialPage1") as! TutorialPage1ViewController
        let secondView = storyboard?.instantiateViewController(withIdentifier: "TutorialPage2") as! TutorialPage2ViewController
        pages = [firstView, secondView]
        let startingViewController = self.pages[0]
        let viewControllers: [UIViewController] = [startingViewController]
        self.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.forward, animated: true, completion: {(done: Bool) in})
    }

    func viewControllerAtIndex(index:NSInteger) -> UIViewController {
        return pages[index]
    }
}

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

    guard let viewControllerIndex = pages.index(of: viewController) else { return nil }

        let previousIndex = viewControllerIndex - 1

        guard previousIndex >= 0          else { return pages.last }

        guard pages.count > previousIndex else { return nil        }

        return pages[previousIndex]
    }

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?
    {
        guard let viewControllerIndex = pages.index(of: viewController) else { return nil }

        let nextIndex = viewControllerIndex + 1

        guard nextIndex < pages.count else { return pages.first }

        guard pages.count > nextIndex else { return nil         }

        return pages[nextIndex]
    }
}

extension TutorialPageViewController: UIPageViewControllerDelegate { }

我的viewDidLoad方法中的print语句没有被调用,所以我不明白我在做什么错。我已经从登录视图控制器创建了一个推送到TutorialPageViewController的segue,但从未加载任何内容。

任何帮助表示赞赏。

最佳答案

尝试在GitHub Repo下面检查示例项目:

链接-https://github.com/RockinGarg/Stack_PageVC.git

包含两种不同的访问方式

1. Making use of Container View and PageVC as SubView

2. Using Segue

关于ios - 是否可以选择UIPageViewController?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49725287/

10-09 16:31