我正在尝试使用PageviewController
. 我有4个ViewControllers
,但它们都不一样。在一个我有一个图像,在第二个我有一个 tableview,......
我想用pageviewController
. 所以我做的是以下。我已将它们添加到modelArray
.
ViewOneViewController *viewOne = (ViewOneViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"ViewOne"];
ViewTwoViewController *viewTwo = (ViewTwoViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"ViewTwo"];
ViewThreeViewController *viewThree = (ViewThreeViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"ViewThree"];
ViewFourViewController *viewFour =(ViewFourViewController *) [self.storyboard instantiateViewControllerWithIdentifier:@"ViewFour"];
self.modelArray = [[NSMutableArray alloc] initWithObjects:viewOne,viewTwo,viewThree,viewFour,nil];
接下来我像这样设置我的 pageviewController。
ViewOneViewController *cVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewOne"];
NSArray *viewControllers = [NSArray arrayWithObject:cVC];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
现在浏览 pageviewViewController 我有以下功能。
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
indexValue--;
if (indexValue < 0) {
return nil;
}
return [self.modelArray objectAtIndex:indexValue];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
indexValue++;
if (indexValue > self.modelArray.count) {
NSLog(@"crash");
return nil;
}
return [self.modelArray objectAtIndex:indexValue];
}
我已声明并综合indexValue
为int
. 但由于某种原因,它有时会向我显示两次 ViewOneController 或者它从 ViewOneController 转到 ViewThreeController 等等。
有人能帮我吗?
亲切的问候
编辑
当我这样做时。
[self.pageViewController setViewControllers:self.modelArray direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
它因此错误而崩溃
'提供的视图控制器数量 (4) 与请求的转换所需的数量 (1) 不匹配'