Ios UIPageViewController设置ViewController导致应用程序崩溃

Ios UIPageViewController设置ViewController导致应用程序崩溃,ios,objective-c,uipageviewcontroller,Ios,Objective C,Uipageviewcontroller,我在一个方法中设置了一个-(void)setViewControllers:(NSArray*)viewcontrollerdirection:(UIPageViewControllerNavigationDirection)方向动画:(BOOL)动画完成:(void(^)(BOOL finished))完成。无论何时调用该方法,它都不会转到下一页。相反,它会转到UIPageViewController情节提要,然后崩溃。我不确定我做错了什么。我用的是pageviewcontroller,是吗

我在一个方法中设置了一个
-(void)setViewControllers:(NSArray*)viewcontrollerdirection:(UIPageViewControllerNavigationDirection)方向动画:(BOOL)动画完成:(void(^)(BOOL finished))完成。无论何时调用该方法,它都不会转到下一页。相反,它会转到UIPageViewController情节提要,然后崩溃。我不确定我做错了什么。我用的是pageviewcontroller,是吗

这是我的密码:

UIViewController *viewcont = [[UIViewController alloc]init];

NSArray *viewControllers = [NSArray arrayWithObject:viewcont];

[self setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
谢谢

共有3个故事板,均符合MSPageViewControllerChild的要求,并合成了pageIndex属性。IntroPageViewController是第一个故事板(p1)

PagingViewController.h:

    //
//  PagingViewController.m
//  MordechaiLevi
//
//  Created by Mordechai Levi on 4/10/14.
//  Copyright (c) 2014 Mordechai Levi. All rights reserved.
//

#import "PagingViewController.h"
#import "IntroPageViewController.h"
#import "MSPageViewController.h"

@interface PagingViewController ()

@end

@implementation PagingViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.device = [UIDevice currentDevice];

    self.device.proximityMonitoringEnabled = YES;

    if (self.device.proximityMonitoringEnabled == YES) {

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sensorCovered) name:@"UIDeviceProximityStateDidChangeNotification" object:nil];

    }else{

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Uh Oh!" message:@"To use this app you need a device with a proximity sensor." delegate:self cancelButtonTitle:@"Got it" otherButtonTitles:nil, nil];

        [alert show];
    }

    self.view.backgroundColor = [UIColor colorWithRed:0.2 green:0.859 blue:0.643 alpha:1.0];

}


- (UIStatusBarStyle)preferredStatusBarStyle {

    return UIStatusBarStyleLightContent;
}

- (void)sensorCovered {

    if (self.device.proximityState == YES) {

        IntroPageViewController *viewcont = [[IntroPageViewController alloc]init];

        NSArray *viewControllers = [NSArray arrayWithObject:viewcont];

        [self setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];


        NSLog(@"sensor covered");

    }else{

        NSLog(@"sensor not covered");
    }
}




- (NSArray *)pageIdentifiers {

    return @[@"p1", @"p2", @"p3"];
}


@end

看起来您正在使用
MSPageViewController
,控制器不符合
MSPageViewControllerChild

从文件中:

它们中的每一个[控制器]都必须是符合MSPageViewControllerChild的类(如果不需要添加任何额外功能,可以使用MSPageViewControllerPage)


你能添加崩溃日志吗?@shannoga刚刚将它添加到问题中添加一个异常断点,然后查看崩溃发生的位置。@LeoNatan崩溃是由
NSArray*viewControllers=[NSArray arrayWithObject:viewcont]发生的。但我不知道如何解决这个问题。有什么想法吗?你发布的代码都与坠机事件无关。您试图在何处设置属性或调用名为
pageIndex
的方法?我的所有页面都符合
MSPageViewControllerChild
或正在使用
MSPageViewCotrollerPage
。我的故事板是
MSPageViewControllerChild
MSPageViewCotrollerPage
的混合体。非常感谢您的回答,谢谢您合成了
pageIndex
属性吗?是的,我刚刚在UIViewController*viewcont=[[UIViewController alloc]init]中更改了UIViewController;到符合MSPageViewControllerChild的类。应用程序不会崩溃,但不会转到下一页。它只是转到一个空白页(根据我对UIPageViewController情节提要的理解)。谢谢。有什么办法解决吗?崩溃已经解决了。你提到的似乎是另一个问题。您是否可以创建一个不同的问题,其中包含更多关于您用于在页面之间切换的代码的上下文?