gpt4 book ai didi

ios - 如何更新 UIPageViewController 页面控件计数

转载 作者:行者123 更新时间:2023-11-28 09:09:39 24 4
gpt4 key购买 nike

我有一个带有页面控件的 UIPageViewController。在委托(delegate)中,我实现了以下方法:

  • presentationCountForPageViewController:
  • presentationIndexForPageViewController:

这很有效,但是总页数可以改变,并且在这种情况下页面控件中显示的点数不会改变。

发生这种情况时,如何告诉页面 View Controller 调用 presentationCountForPageViewController: 来更新点的总数?

最佳答案

原来这是使用 NSFetchedResultsController 作为页面数据源的结果。在我调用 UIPageViewController 上的 setViewControllers:direction:animated:completion: 之前,NSFetchedResultsController 的计数没有得到更新。

解决方法是在 controllerDidChangeContent: 中调用以下函数来强制更新页面控件。

func refreshPageController() {
let controllers = pageController.viewControllers
if controllers.count > 0 {
pageController.setViewControllers(controllers, direction: .Forward, animated: false, completion: nil)
}
}

更新:

虽然上面的解决方案有效,但它破坏了我在删除页面时用来滚动到下一页的动画。

更好的解决方案:在调用 setViewControllers:direction:animated:completion: 之前等待页面删除提交给 Core Data。

关于ios - 如何更新 UIPageViewController 页面控件计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29686970/

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