I know that there are several other questions like this, but i couldn't find a solution for my problem. I use a pageViewController which displays different ViewControllers. Every time the pageViewController moves forward I check the input of the lastPage. If it's wrong the pageViewController should go back to that page by using the setViewController method. Without this method everything works fine but if I try to use it the app crashes with the following exception:
19:48:25.596 Phook[23579:60b] *** Assertion failure in -[_UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:], /SourceCache/UIKit_Sim/UIKit-2935.137/_UIQueuingScrollView.m:383
2014-06-02 19:48:25.600 Phook[23579:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: [views count] == 3'
And here's my code:
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished
previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
if (completed && finished)
{
RegisterUserPageContent* lastPage = (RegisterUserPageContent*)previousViewControllers[ previousViewControllers.count-1];
int lastIndex = lastPage.pageIndex;
int newIndex = ((RegisterUserPageContent*)[self.pageViewController.viewControllers objectAtIndex:0]).pageIndex;
if (newIndex > lastIndex)
{ // Moved Forward
if(!lastPage.testInput)
{
[self.pageViewController setViewControllers:@[ [self.storyboard instantiateViewControllerWithIdentifier:_pageStoryBoardIDs[0]] ]
direction:UIPageViewControllerNavigationDirectionReverse
animated:YES completion:nil];
}
}
else
{ // Moved Reverse
}
}
}
As I already said. I searched a lot and implemented some solutions but nothing helped. Thanks.
Well it's 2018 and the bug is still around. I tried all the solutions above, but none worked for me. And after many tries, setting the animation parameter to false, was what worked for me in swift 4
Then it was just a matter of setting a custom transition. Hope it helps others in the same situation.
I get this problem today.
I start an animation when UIPageController switch viewController.
Program will crash if
animation:YES
,but ifanimation:NO
it will be fine.I guess we cant do two animations as the same time. But if you want
animation:YES
,you can do your other animation after switch viewControlle's,such as use GCD after.In addition to
I had to also place this following code within a DispatchQueue.main.async
Because I was enable/disabling scrolling until users completed filling out values on previous pages, before allowing them to go to the next page