UIPageViewController 缓存问题
UIPageViewController caching issue
我正在使用 UIPageViewController 在五个非常相似的页面之间滚动。我正在使用应用程序委托在调用 applicationWillEnterForeground 时刷新视图。 (它通过在我的 PageViewController 中调用 viewDidLoad 来实现。)
我将 PageViewController 的当前索引存储在 NSUserDefault 变量中。但这就是问题所在。显然,UIPageViewController 使用缓存,这意味着它并不总是调用它的方法,这意味着我存储的索引号很少是正确的。
结果是,当我关闭应用程序并重新打开它时,它会刷新视图并显示与我存储的最后一个索引关联的任何页面 - 这通常不是当前索引。
那么我的问题是,当我的应用程序重新进入前台时,刷新当前视图的最佳方式是什么?
解决方法:使用委托方法:
- pageViewController:willTransitionToViewControllers:
获取当前索引就这么简单
let index = (pendingViewControllers[0] as! ViewController).index
我正在使用 UIPageViewController 在五个非常相似的页面之间滚动。我正在使用应用程序委托在调用 applicationWillEnterForeground 时刷新视图。 (它通过在我的 PageViewController 中调用 viewDidLoad 来实现。)
我将 PageViewController 的当前索引存储在 NSUserDefault 变量中。但这就是问题所在。显然,UIPageViewController 使用缓存,这意味着它并不总是调用它的方法,这意味着我存储的索引号很少是正确的。
结果是,当我关闭应用程序并重新打开它时,它会刷新视图并显示与我存储的最后一个索引关联的任何页面 - 这通常不是当前索引。
那么我的问题是,当我的应用程序重新进入前台时,刷新当前视图的最佳方式是什么?
解决方法:使用委托方法: - pageViewController:willTransitionToViewControllers:
获取当前索引就这么简单
let index = (pendingViewControllers[0] as! ViewController).index