我有一个UIPageViewController,我已经设置了一个数组作为数据源。我看到第一页正常,并且演示计数点正确显示,但是当我尝试拖动到下一页时没有任何反应。因此,我在viewControllerAfterViewController
和Before
方法中设置了一些断点,并且它们永远不会被调用。 presentationCountForPageViewController
的其他dataSource方法被调用。
知道我错过了什么吗?我已经在网上找到了我在网上找到的但却无法找到的例子。
- (void)viewDidLoad
{
[super viewDidLoad];
UIPageViewController *pageController = self.pageController;
pageController.dataSource = self;
UIChildViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[initialViewController];
[pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
[self addChildViewController:pageController];
[self.view addSubview:pageController.view];
[pageController didMoveToParentViewController:self];
}
- (UIPageViewController *)pageController
{
return !_pageController ? _pageController =
({
UIPageViewController *value = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
value.view.frame = self.view.bounds;
value;
}) : _pageController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pa geViewController viewControllerBeforeViewController:(UIChildViewController *)viewController
{
NSUInteger index = viewController.index;
return (index == 0 ) ? nil : [self viewControllerAtIndex:--index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIChildViewController *)viewController
{
NSUInteger index = viewController.index;
index++;
return (index == self.myDataSourceArray.count) ? nil : [self viewControllerAtIndex:index];
}
- (UIChildViewController *)viewControllerAtIndex:(NSUInteger)index
{
UIChildViewController *childViewController = [UIChildViewController new];
childViewController.view.frame = self.pageController.view.bounds;
childViewController.index = index;
...
return childViewController;
}
- (NSInteger)presentationCountForPageViewController: (UIPageViewController *)pageViewController
{
// The number of items reflected in the page indicator.
return self.myDataSourceArray.count;
}
- (NSInteger)presentationIndexForPageViewController:(UI PageViewController *)pageViewController
{
// The selected item reflected in the page indicator.
return 0;
}
答案 0 :(得分:2)
问题在于,在包含封装UIPageViewController的UIViewController子类时,我忘记在父视图控制器的let FunctionFactory<'T> =
let s = 0.0 |> Seq.unfold (fun i -> Some(i, if 0.0 = i then 1.0 else 0.0))
(fun (ignoredParam:'T) -> Seq.next s )
中包含viewDidLoad
和addChildViewController
didMoveToParentViewController
解决了问题。