UIPageViewController delegate method not called

允我心安 提交于 2020-01-14 09:07:34

问题


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.


回答1:


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;



回答2:


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.




回答3:


How did you connect the page view controller's delegate outlet? My guess is that you never connected the delegate link.

It's odd to have a page view controller be it's own data source and delegate. I've never tried to do that, as you are doing, and am not sure it would work. I always set up a container view controller that manages the page view controller. With storyboards you just set up a container view in IB and connect an embed segue. Then you'd make the container view controller the data source and/or delegate.




回答4:


Just spent some time trying to figure out why didFinishAnimating was not called. My delegates were set right but it turns out that in Swift 3 the function goes like that :

func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)

Mind the above underscore. The function below won't be called.

func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)


来源:https://stackoverflow.com/questions/22067476/uipageviewcontroller-delegate-method-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!