问题描述
过去几天我一直在努力解决这个问题,经过所有这些杂耍,我发现我只需要数据源方法的当前索引来更新当前可见的页码
I have been struggling with this issue for the last few days and after all this juggling I have figured out that all I need is the current Index from the datasource method to update with current visible page number
我有这个 UIPageViewController
数据源方法,我需要使用当前索引来获取委托方法的当前可见页面previousViewControllers transitionCompleted:(BOOL)完成
I have this UIPageViewController
datasource method and I need to use the current index to get the current visible page for delegate method previousViewControllers transitionCompleted:(BOOL)completed
- (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];
return contentViewController;
}
我对如何将当前索引语句从datasource方法写入委托方法更新当前可见页面。
I'm confused about how to write the current index statement from datasource method into delegate method to update current visible page.
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed{
if (!completed)
{
return;
}
//currentIndex = [[self.pageViewController.viewController lastObject]];
currentIndex = [self indexOfObject:contentViewController];
[self displaycurrentIndex:currentIndex];
//self.pageControl.currentPage = currentIndex;
}
我该如何更正?
推荐答案
看起来您应该能够获得当前索引:
It looks like you should be able to get the current index with:
ContentViewController *viewController = [self.pageViewController.viewControllers lastObject];
currentIndex = [modelArray indexOfObject:[viewController page]];
这篇关于UIPageViewController:获取currentPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!