我已经将UIPageViewController子类化了,它运行正常。除了前后加载页面的新实例,而不是(正如我所料)检索它先前加载的实例。 Aren的引用应该是强大的吗?
以下是我的代码。
感谢您的帮助。
皮埃里克
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
}
}
答案 0 :(得分:0)
似乎错误的功能在FirstViewController,SecondViewController,ThirdViewController中。当我写我的问题时,视图控制器按照方法“viewWillAppear”加载视图。 只要我将代码移动到“viewDidLoad”,视图就会停止加载多次。