gpt4 book ai didi

swift - UIPageViewController多次加载ChildViews

转载 作者:行者123 更新时间:2023-11-30 14:03:06 25 4
gpt4 key购买 nike

我已经对 UIPageViewController 进行了子类化,并且它工作正常。除了来回加载页面的新实例这一事实之外,而不是(如我所期望的那样)检索之前加载的实例。引用不是应该很强吗?

以下是我的代码。

感谢您的帮助。

皮里克

class CustomPageViewController: UIPageViewController, UIPageViewControllerDataSource {

var view1: FirstCustomViewController!
var view2: SecondCustomViewController!
var view3: ThirdCustomViewController!
var views = []

override func viewDidLoad() {
super.viewDidLoad()

self.dataSource = self;

self.view1 = FirstViewController()
self.view2 = SecondViewController()
self.view3 = ThirdViewController()

self.views = [self.view1, self.view2, self.view3]
self.setViewControllers([self.view1], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
}

// MARK: - PageViewControllerDataSource

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

let index = self.views.indexOfObject(viewController)

if (index > 0) {
return self.views.objectAtIndex(index-1) as? UIViewController
}

return nil
}

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

let index = self.views.indexOfObject(viewController)

if (index < self.views.count-1) {
return self.views.objectAtIndex(index+1) as? UIViewController
}

return nil
}
}

最佳答案

似乎有问题的函数在 FirstViewController、SecondViewController、ThirdViewController 中。当我写下我的问题时, View Controller 按照“viewWillAppear”方法加载 View 。当我将代码移至“viewDidLoad”时, View 多次停止加载。

关于swift - UIPageViewController多次加载ChildViews,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32746407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com