老问题,但以下实现调用委托和数据源方法来转到上一页或下一页(但不检查是否设置了委托或数据源):
- (IBAction)navigateReverse:(id)sender
{
UIViewController *controller = [self.dataSource pageViewController:self viewControllerBeforeViewController:self.designViewControllers[self.currentIndex]];
if (!controller)
{
return;
}
NSArray *newViewControllers = @[controller];
NSArray *previousViewControllers = self.viewControllers;
__weak __typeof(self) weakSelf = self;
[self.delegate pageViewController:self willTransitionToViewControllers:newViewControllers];
[self setViewControllers:newViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {
[weakSelf.delegate pageViewController:weakSelf didFinishAnimating:finished previousViewControllers:previousViewControllers transitionCompleted:finished];
}];
}
- (IBAction)navigateForward:(id)sender
{
UIViewController *controller = [self.dataSource pageViewController:self viewControllerAfterViewController:self.designViewControllers[self.currentIndex]];
if (!controller)
{
return;
}
NSArray *newViewControllers = @[controller];
NSArray *previousViewControllers = self.viewControllers;
__weak __typeof(self) weakSelf = self;
[self.delegate pageViewController:self willTransitionToViewControllers:newViewControllers];
[self setViewControllers:newViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {
[weakSelf.delegate pageViewController:weakSelf didFinishAnimating:finished previousViewControllers:previousViewControllers transitionCompleted:finished];
}];
}