I'm trying to implement UIPageViewController
with validation on every step. My code was working fine without validation, so everything with pages seems to be done right. This is my code:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
int index = [(MyViewController *) viewController index];
index--;
return [_viewModel viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
BOOL isDataValid = [(MyViewController *) viewController validateData];
if (isDataValid) {
int index = [(MyViewController *) viewController index];
index++;
return [_viewModel viewControllerAtIndex:index];
}
return nil;
}
My problem is that when step 1 is shown, viewControllerAfterViewController
is called to prepare step 2, but because step 2 cannot be valid (user didn't have chance to input data) so it is returning nil. I would like UIPageViewController
to call viewControllerAfterViewController
every time user tries to swipe to the next screen and not give up after receiving a nil. Is it doable?