【问题标题】:UIPageViewController caching issueUIPageViewController 缓存问题
【发布时间】:2016-06-02 08:15:51
【问题描述】:

我正在使用 UIPageViewController 在五个非常相似的页面之间滚动。每当调用 applicationWillEnterForeground 时,我都会使用应用程序委托刷新视图。 (它通过在我的 PageViewController 中调用 viewDidLoad 来实现。)

我将 PageViewController 的当前索引存储在 NSUserDefault 变量中。但这就是问题所在。显然,UIPageViewController 使用了缓存,这意味着它并不总是调用它的方法,这意味着我存储的索引号很少是正确的。

结果是,当我关闭应用程序并重新打开它时,它将刷新视图并显示与我存储的最后一个索引相关联的任何页面 - 通常不是当前索引。

然后我的问题是,当我的应用重新进入前台时,刷新当前视图的最佳方式是什么?

【问题讨论】:

    标签: ios swift uipageviewcontroller


    【解决方案1】:

    解决方案:使用委托方法: - pageViewController:willTransitionToViewControllers:

    获取当前索引很简单

    let index = (pendingViewControllers[0] as! ViewController).index
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-22
      • 2011-08-12
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 2020-11-04
      • 2011-10-30
      相关资源
      最近更新 更多