在导航栏上显示页码时不一致
问题 #
在第一页上显示 0 of 20
显示 1 of 20 使用
[self displaycurrentIndex:1];
在 viewDidload 方法中。
在第二页显示 1 of 20,在第三页显示 2 of 20,在第四页 3 of 20 ........
当页面以相反的顺序翻页时,它会在第一页显示 0 of 20,而不是 1 of 20。
发行#
当我单击页面将其翻转时,它会更改当前页码,这是错误的,因为它应该仅在下一页显示时才显示下一个当前页码,而不是在页面即将显示下一页时
使用实例 displaycurrentIndex 方法显示当前页码
- (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;
}
我怎样才能解决这个问题。
感谢帮助。