pageviewcontroller的currentIndex显示不正确

时间:2013-07-18 15:11:29

标签: iphone objective-c ios6 uipageviewcontroller

在导航栏上显示页码时不一致

问题#

在第一页上显示0 of 20

使用

显示20个中的1个
[self displaycurrentIndex:1];

在viewDidload方法中。

在第二页显示20中的1,在第三页上显示20中的2,在20的第4页中显示........

当页面以相反的顺序翻转时,它在第一页上显示20的20而不是20中的1。

Isuue#

当我点击页面将其翻过来时,它会更改当前页码,这是错误的,因为只有当页面即将显示下一页时才显示下一页当前页码

使用实例displaycurrentIndex方法显示currentpagenumber

- (void) displaycurrentIndex:(NSUInteger)currentIndex {

self.navigationItem.title = [NSString stringWithFormat:
                             @"Page %i of %i",
                             currentIndex,
                             CGPDFDocumentGetNumberOfPages(PDFDocument)];
}

在viewDidload方法

 [self currentIndex:1];

使用pageviewcontroller数据源方法显示当前页码

#pragma mark - UIPageViewControllerDataSource Methods

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController 
      viewControllerBeforeViewController:(UIViewController *)viewController {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"pages" ofType:@"pdf"];

    NSURL *pdfurl = [NSURL fileURLWithPath:path];
    PDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfurl);

    contentViewController = [[ContentViewController alloc] initWithPDFAtPath:path];

    currentIndex = [modelArray indexOfObject:[(ContentViewController *)viewController page]];

    if (currentIndex == 0) {

        return nil;

    }

    contentViewController.page = [modelArray objectAtIndex:currentIndex - 1];

     [self displaycurrentIndex:currentIndex - 1];

    return contentViewController;

}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
       viewControllerAfterViewController:(UIViewController *)viewController {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"pages" ofType:@"pdf"];

    NSURL *pdfurl = [NSURL fileURLWithPath:path];
    PDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfurl);

    contentViewController = [[ContentViewController alloc] initWithPDFAtPath:path];

    currentIndex = [modelArray indexOfObject:[(ContentViewController *)viewController page]];

    if (currentIndex == totalPages - 1) {

        return nil;
    }
    contentViewController.page = [modelArray objectAtIndex:currentIndex + 1];

    [self displaycurrentIndex:currentIndex + 1];

    return contentViewController;

}

我该如何解决这个问题。

感谢您的帮助。

0 个答案:

没有答案