I found a strange problem with two methods of UIPageViewControllerDataSource : when I first enter the pageview controller and drag the contents of the controller, regardless of the direction of the drag, both data source methods get called. I believe that when I am on the first page and drag to the right, this means that the page will no longer be in front of the first page, none of the methods should be called. And if I drag left, only the calling method should receive the call.
I completed this post to configure view controllers (except that I do not have a separate pageview controller on the storyboard. I used the traditional [UIPAgeViewController alloc] init] method to create the controller instance). Below is my code:
For a view controller that actually displays the contents of the page view controller (only the corresponding part of viewDidLoad ):
- (void)viewDidLoad { // initialize page view controller _pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; self.pageViewController.delegate = self; self.pageViewController.dataSource = self; // set up the initial scene of the page view controller UIViewController *viewController = [self viewControllerAtIndex:0]; [self.pageViewController setViewControllers:@[viewController] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; // adjust the size of the page view controller, -44 to show the buttons at the bottom self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 44); // display the content of the page view controller [self addChildViewController:self.pageViewController]; [self.view addSubview:self.pageViewController.view]; [self.pageViewController didMoveToParentViewController:self]; } - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { NSUInteger index = ((PWCPageContentViewController *)viewController).index; if (index == 0 || index == NSNotFound) { return nil; } --index; return [self viewControllerAtIndex:index]; } - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { NSUInteger index = ((PWCPageContentViewController *)viewController).index; if (index == self.numberOfPages - 1 || index == NSNotFound) { return nil; } ++index; return [self viewControllerAtIndex:index]; } - (PWCPageContentViewController *)viewControllerAtIndex:(NSUInteger)index { PWCPageContentViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageContentViewController"]; viewController.index = index; NSString *text = [self.notes getNoteAtIndex:index]; [viewController.textView setText:text]; return viewController; }
For PWCPageContentViewController.h:
For PWCPageContentViewController.m:
So, is this a known problem or am I missing something?
ios objective-c uipageviewcontroller
ljiatu
source share