Open D-32 opened 9 years ago
hey there,
I have been facing the same issue and came up with a solution of quality proportional to the amount of time I had to investigate the issue. tl;dr - lame but works.
You need to change that :
-(void)viewWillAppear:(BOOL)animated {
[self setupPageViewController];
[self setupSegmentButtons];
CGRect sizeRect = [UIScreen mainScreen].applicationFrame;
float width = sizeRect.size.width;
NSInteger xCoor = (width/[viewControllerArray count])*self.currentPageIndex-X_OFFSET;
selectionBar.frame = CGRectMake(xCoor, selectionBar.frame.origin.y, selectionBar.frame.size.width, selectionBar.frame.size.height);
}
And then update the first view controller that is being loaded currentPageIndex.
-(void)setupPageViewController {
pageController = (UIPageViewController*)self.topViewController;
pageController.delegate = self;
pageController.dataSource = self;
[pageController setViewControllers:@[[viewControllerArray objectAtIndex:self.currentPageIndex]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
[self syncScrollView];
}
Not sure if it was a bug or by design but in my case pushing anything on top of the navigation and then going back was causing some rather unintuitive behaviour.
The setup code inside
viewWillAppear
should only be performed once. Inside my app it happens that I push a view controller and when navigating backviewWillAppear
is called again. This then causes all the pages to be setup again and the current index is reset.