Pregunta

I have a UIPageViewController with 7 pages. The user must enter all the required fields in each page before going to the next page. If the user doesn't enter a required field i should display a warning popup and keep the user in the same page if he tries to go to the next page. Does anyone know how i can cancel page swipe and keep the user in the same page if the user doesn't enter a required field?

Thanks, Anand.

¿Fue útil?

Solución

If you have a datasource for the pageviewcontroller, you can return nil for the method:

    - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController

You are probably setting all viewcontrollers from start, but to do this you will need to set the initial viewcontroller, and provide the next and previous viewcontrollers from the datasource methods.

It will not disable the scrolling in the scrollview, meaning the user can scroll and 'bounce' against last page.

EDIT: Please note that UIPageViewController does cache answers from it's datasource; When you return an answer for a given index, it will not ask for it again till scroll goes sufficiently far or you manually set the viewControllers.

For your refresh to work, as a workaround, you could call:

pageViewcontroller setViewControllers:[pageViewcontroller viewControllers]                                     direction:UIPageViewControllerNavigationDirectionForward
                                       animated:NO
                                     completion:nil];

to make it drop the caches and request the controller from your datasource again. (Thanks Douglas Hill)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top