我有一个带页面卷曲的UIPageViewController(并不是转换类型不重要),其中第二页在动画完成之前不会显示。代码用于工作,但不再是,任何想法都会很棒
代码如下:
- (void)viewDidLoad
{
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
// other code deleted, for easy reading
}
- (PsalmViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.mDelegate.mPsalms count] == 0) || (index >= [self.mDelegate.mPsalms count]))
return nil;
// Create a new view controller and pass suitable data.
PsalmViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"PsalmViewController"];
PsalmData *data = [self.mDelegate.mPsalms objectAtIndex:index];
[controller setupView:index psalm:data];
self.mNextPsalm = controller;
return controller;
}
#pragma mark - Page View Controller Data Source
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
if (self.mNextIndex == 0 || self.mNextIndex == NSNotFound)
return nil;
self.mNextIndex = self.mPageIndex - 1;
self.mAnimating = true;
NSLog(@"Prev %lud", (unsigned long)self.mNextIndex);
return [self viewControllerAtIndex:self.mNextIndex];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
if (self.mNextIndex == NSNotFound)
return nil;
if (self.mNextIndex + 1 == [self.mDelegate.mPsalms count])
return nil;
self.mNextIndex = self.mPageIndex + 1;
self.mAnimating = true;
NSLog(@"Next %lu", (unsigned long)self.mNextIndex);
return [self viewControllerAtIndex:self.mNextIndex];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.mDelegate.mPsalms count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed
{
if (completed)
{
self.mPageIndex = self.mNextIndex;
[self setCurrentPsalm:self.mNextPsalm];
}
else if (finished)
{
self.mNextIndex = self.mPageIndex;
}
if (completed || finished)
self.mAnimating = false;
NSLog(@"C %d F %d", completed, finished);
}
再次感谢任何帮助,我不知道是什么导致了这个问题。