I'm trying to update the current page in UIPageViewController
during rotation as following:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSArray *controllers = @[someViewController];
UIPageViewControllerNavigationDirection direction = UIPageViewControllerNavigationDirectionForward;
[self.pageController setViewControllers:controllers direction:direction animated:YES completion:^(BOOL finished) {
/// This completion block isn't called ever in this case.
}];
}
But, for some reason, the completion block isn't called ever in this case, while it's called as expected when I call the same method with same parameters from other places.
Could anyone confirm this strange behavior, and if it's a bug in UIPageViewController
or just a misuse of me?
Update
I found out that if I change the parameter animated
to NO
the completion block will be called as expected! So, it seems more to me that it's a bug with UIPageViewController
.
Having the same issue, found the following thing: if someViewController
is the current visible controller or pageController.viewControllers?.first
and animated
flag is set to true, then setViewControllers
is called without invoking the completion handler. The easiest way is to call setViewControllers
with animated
flag set to false. No animations will be shown, but the completion handler will be invoked anyway. But in most cases you need animations to be shown. Thus, the only possible workaround here is to check if the viewController to be set isn't the visible one. If it is, you should call setViewControllers
with animated
flag set to false:
let completionBlock: (Bool) -> Void
let isAnimated = (newController != pageController.viewControllers?.first)
pageController.setViewControllers([newController],
direction: .forward,
animated: isAnimated,
completion: completionBlock)
Hope that helps you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With