Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPageViewController delegate method not called

In my application I have a RootViewController (UIPageViewController), a FirstController (UIViewController) and a SecondController (UIViewController). The two views inside the two UIViewControllers scroll over the RootViewController.

In my RootViewController.h:

@interface RootController : UIPageViewController <UIPageViewControllerDataSource, UIPageViewControllerDelegate>

But when I scroll between different views delegate methods like:

-(void) pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed

are not called. Why? Can someone help me? Thank you in advance.

like image 601
charles Avatar asked Feb 27 '14 11:02

charles


2 Answers

Did you assign rootViewController (whichever controller/object you want to receive the delegate calls) to be the delegate/datasource of the UIPageViewController?

pageViewController.delegate = rootViewController;
pageViewController.dataSource = rootViewController;
like image 196
Wilmar Avatar answered Oct 21 '22 11:10

Wilmar


In addition to the obvious solution above, if you are encountering this issue please consider the possibility that the PageViewController itself is not being retained. I made the mistake earlier this evening of instantiating a PageViewController and adding its view as a subView but not retaining the pageViewController itself.

Make sure to retain it either by adding it as a childViewController or assigning it to a strong property.

like image 41
dave Avatar answered Oct 21 '22 11:10

dave