In my code I do sometimes "reset" UIPageViewController by using the construct as given below:
id vc = [pageViewController.viewControllers firstObject];
__weak UIPageViewController *pvc = pageViewController;
__weak MyViewController *weakSelf = self; // UIViewController subclass which is hosting pageViewController
pageViewController.dataSource = nil;
[pageViewController setViewControllers: @[ [[UIPageViewController alloc] init] ]
direction: UIPageViewControllerNavigationDirectionForward
animated: NO completion: ^(BOOL completed) {
[pvc setViewControllers: @[ vc ] direction: UIPageViewControllerNavigationDirectionForward
animated: NO completion: ^(BOOL completed) {
pvc.dataSource = weakSelf;
}];
}];
This works perfectly almost all the time, but recently, when I was fast swiping pages back and forth, the app has crashed with NSInternalInconsistencyException caused in:
*** Assertion failure in -[UIPageViewController queuingScrollView:didEndManualScroll:toRevealView:direction:animated:didFinish:didComplete:], /SourceCache/UIKit/UIKit-3318.16.14/UIPageViewController.m:1875
The crash was caused by reset code being invoked from viewWillLayoutSubviews method of a view controller which is hosting UIPageViewController. The reason was: "No view controller managing visible view: (here goes my custom view)". This custom view is only created within vc instances - view controllers that are passed to UIPageViewController. So I don't think it's possible for them to exist without this view controller. I am not able to reproduce this issue, but I believe it can happen again, at random.
What can be the real reason for this happening?
Is this a bug in UIKit?
Are there any workarounds?