iOS UIPageViewController - 由于未捕获的异常而终止应用程序'无效参数不满足:[views count] == 3'

时间:2013-10-12 18:26:19

标签: ios runtime-error uipageviewcontroller


我有一个页面视图控制器,我收到错误Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: [views count] == 3'

这是我的数据源:

//
//  MSABDrawingPageModelController.m
//  My Special Alphabet Book
//
//  Created by Ari Porad on 9/3/13.
//  Copyright (c) 2013 Cari Books. All rights reserved.
//

#import "MSABDrawingPageModelController.h"
#import "MSABDrawingViewController.h"
#import "MSABDrawingView.h"

@implementation MSABDrawingPageModelController

-(id)initWithLetter:(MSABLetter *)letter{
    if (self = [super init]) {
        self.letter = letter;
    }
    return self;
}

-(id)init{
    return [self initWithLetter:nil];
}

-(NSURL *)docsDirUrl{
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] objectAtIndex:0];
}

-(UIViewController *)viewControllerAtIndex:(int)index{
    MSABDrawingViewController *VC = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"MSAB_DRAWING_VIEW_CONTROLLER"];

    ((MSABDrawingView *) VC.view).points = [NSMutableArray arrayWithArray:@[[NSMutableArray array]]];
    VC.index = index;
    VC.letter = self.letter;

    return VC;
}

#pragma mark -
#pragma mark Page View Controller Data Source Methods

-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
    UIViewController *vc = [self viewControllerAtIndex:((MSABDrawingViewController *)viewController).index + 1];
    if(vc == nil){
        vc = [[MSABDrawingViewController alloc] init];
    }
    NSLog(@"AVC: %@", vc);
    return vc;
}

-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController{
    UIViewController *vc = [self viewControllerAtIndex:((MSABDrawingViewController *)viewController).index - 1];
    if(vc == nil){
        vc = [[MSABDrawingViewController alloc] init];
    }
    NSLog(@"PVC: %@", vc);
    return vc;
}

@end

如果您还需要了解其他信息,请与我们联系。

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。

事实证明,你必须设置uipageviewcontroller的初始视图控制器,无论你是通过IB还是以编程方式设置它。

来源: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/PageViewControllers.html#//apple_ref/doc/uid/TP40011313-CH4-SW10

调用setViewControllers:direction:animated:completion:方法并设置初始视图控制器数组。