UIPageViewController setViewController 导致应用程序崩溃 [英] UIPageViewController setViewController causing app to crash

查看:32
本文介绍了UIPageViewController setViewController 导致应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 - (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animation:(BOOL)animated completion:(void (^)(BOOL finished))completion 设置在一个方法上.每当调用该方法时,它都不会转到下一页.相反,它转到 UIPageViewController 故事板然后崩溃.我不确定我做错了什么.我正在使用 MSPageViewController 作为页面视图控制器,可以吗?

I have a - (void)setViewControllers:(NSArray *)viewControllers direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL)animated completion:(void (^)(BOOL finished))completion set up in a method. Whenever the method is called it doesn't go to the next page. Instead, it goes to the UIPageViewController storyboard and then crashes. I'm not sure what I'm doing wrong. I am using MSPageViewController for the pageviewcontroller, could that be it?

这是我的代码:

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

NSArray *viewControllers = [NSArray arrayWithObject:viewcont];

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

谢谢.

有 3 个故事板都符合 MSPageViewControllerChild,并合成了 pageIndex 属性.IntroPageViewController 是第一个故事板 (p1).

There are 3 storyboards all conforming to MSPageViewControllerChild with the pageIndex property synthesized. IntroPageViewController is the first storyboard (p1).

PagingViewController.h:

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.

Looks like you're using MSPageViewController, with a controller that doesn't conform to MSPageViewControllerChild.

来自文档:

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

Each of them [controllers] must be a class that conforms to MSPageViewControllerChild (if you don't need to add any extra functionality to it you can use MSPageViewControllerPage).

这篇关于UIPageViewController setViewController 导致应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆