如果viewControllerBeforeViewController
viewControllerAfterViewController
任一方法返回nil,则也会调用计数器部分。
这种行为是预期的行为吗?无论如何我都可以阻止这种情况发生。这就是我试图做的事情。
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
if ([viewController isKindOfClass:[QuestionViewController class]]){
QuestionViewController* qvc = (QuestionViewController*)viewController;
CVPQuestion* prevQuestion = [_surveyContext previousQuestion:qvc.question];
return [self questionControllerWithQuestion:prevQuestion];
}
if ([viewController isKindOfClass:[SurveyEndedViewController class]]){
return [self questionControllerWithQuestion:[self.questionList lastObject]];
}
return nil;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(QuestionViewController *)viewController {
if ([viewController respondsToSelector:@selector(question)]){
CVPQuestion* nextQuestion = [_surveyContext previousQuestion:viewController.question];
if (nextQuestion == nil && ![_surveyContext isAnswered:viewController.question]){
[viewController showToasterWithText:@"Please answer the question to continue"];
}
QuestionViewController* qc = [self questionControllerWithQuestion:[_surveyContext nextQuestion:viewController.question]];
if (!qc){return [self surveyEndedController:viewController.question];}
return qc;
}
return nil;
}
如果在viewControllerAfterViewController
之后调用viewControllerBeforeViewController
,则也会发送通知[viewController showToasterWithText:@"Please answer the question to continue"];
。
答案 0 :(得分:0)
看起来像UIPageviewcontroller'并没有真正使用' UIScrollViewDelegate'。因此,继承' UIPageViewController'并使用' UIScrollViewDelegate'似乎可以找到它向前滑动或向后滑动的技巧。
//从PageViewController获取滚动视图的scrollView
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
for (UIView* v in [self.view subviews]){
if ([v isKindOfClass:[UIScrollView class]]){
_scrollView = (UIScrollView*)v;
}
}
if (_scrollView){
_scrollView.delegate = self;
}
}
//滚动视图开始拖动时记录内容偏移量
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
_startContentOffset = _scrollView.contentOffset;
_transitionState = SurveyPageviewCtlrTransitionInitiated;
[_transitionStateDelegate transitionInitiated:self];
}
//基于位移的方向
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if (_scrollView.contentOffset.x > _startContentOffset.x){
[self.delegate forwardDrag];
}
else{
[self.delegate reverseDrag];
}