1

I have a UIPageViewController that only ever has two UIViewControllers in. There is a UISegmentControl above the UIPageViewController that changes between the segments "new" and "hot" depending on which page the UIPageViewController is on. This works about 90% of the time, however, if I swipe as indicated in this question, the UIPageViewController gets confused on which page it is on. This results in the UISegmentControl saying "new" when actually the "hot" page is being displayed.

Each view controller is assigned a page index (0 or 1) when it's first instantiated. Then the following code changes the segmented control index:

func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
    if completed,
        let index = (pageViewController.viewControllers?.last as? MyCollectionViewController)?.pageIndex,
        let pageType = PageType(rawValue: index) {
            currentPage = pageType
            segmentedControl.selectedSegmentIndex = index
    }
}

What's weird is that when the bug is occurring, I print out the pageIndex of the pageViewControllers last viewController and it agrees with the segmentedControl index. Yet on screen, it is 100% not the viewController it's claiming is being shown...

Tometoyou
  • 7,792
  • 12
  • 62
  • 108

0 Answers0