UIPageViewController页面指示器不同步

时间:2014-03-17 07:14:56

标签: ios uipageviewcontroller uipagecontrol

使用此UIAutomation脚本快速来回扫描时,我的UIPageViewController页面指示器不同步:

target.dragFromToForDuration({x:10, y:100}, {x:300, y:114}, 0.5);
target.dragFromToForDuration({x:300, y:100}, {x:10, y:114}, 0.5);

一遍又一遍地重复。

或者在页面控制器上点击一个方向并按照此问题滑动另一个方向: UIPageControl and UIPageviewController are out of sync

解决方案是用UIPageControl替换页面指示器。这个解决方案也在这里被接受: Page Indicator UIPageViewController

我返回UIViewControllers的代码(UIViewControllers包含具有不同数据源的表):

- (MyViewController*) viewControllerAtIndex:(NSUInteger)index
{
    MyViewController *pageContentViewController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];

    id myDataSource = [self.myDataSources objectAtIndex:index];
    [pageContentViewController setMyDataSource:myDataSource];

    return pageContentViewController;
}

#pragma mark - Page View Controller Data Source

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    id myDataSource = [((MyViewController*) viewController) myDataSource];
    NSInteger index = [self.myDataSources indexOfObject:myDataSource];

    if (index == NSNotFound || index - 1 < 0) {
        return nil;
    } else {
        MyViewController *pageContentViewController = [self viewControllerAtIndex:index - 1];
        return pageContentViewController;
    }
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    MyDataSource *myDataSource = [((MyViewController*) viewController) myDataSource];
    NSInteger index = [self.myDataSources indexOfObject:myDataSource];

    if (index == NSNotFound || index + 1 >= [self.myDataSources count]) {
        return nil;
    } else {
        MyViewController *pageContentViewController = [self viewControllerAtIndex:index + 1];
        return pageContentViewController;
    }

    return nil;
}

是什么导致UIPageViewController和页面指示器不同步?

0 个答案:

没有答案