是否可以切换到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 语句没有被调用,所以我不明白我做错了什么。我已经创建了一个推送 segue 以从登录视图控制器TutorialPageViewController,但没有任何内容加载。

任何帮助,不胜感激。

尝试在下面的 GitHub 存储库中查看示例项目:

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

包含两种不同的访问方式

1. Making use of Container View and PageVC as SubView 
2. Using Segue

相关内容

  • 没有找到相关文章

最新更新