1


我有一个页面视图控制器,但我收到了错误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

让我知道您是否还有其他需要知道的。

4

1 回答 1

1

我有同样的问题。

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

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

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

于 2013-11-14T06:06:24.030 回答